Monday, 3 November 2008

Programming Jakarta Struts By Chuck Cavaness -Part4

Couple Of Days i started reading Programming Jakarta Struts By Chuck Cavaness.

Nice book written by Chuck Cavaness.

I wanted to share few quotations found from the next 2 chapters(7-8) from this book.

1) In a general sense, a view represents a display of the domain model in a user interface. There can be many different views of the same model. The domain model contains the business entities, which hold the state for the application. Metaphorically speaking, a view is a window that clients can use to look at the state of the model, and the perspective may be different depending on which window a client looks through.

2) The DTO pattern is used quite frequently in J2EE applications, where distributed components making remote calls can suffer serious performance setbacks from using too many remote invocations. It is used in other technologies as well, under different names and guises.

A DTO is a coarse-grained view of what is typically fine-grained information. It aggregates various attributes from one or more business entities and puts this information into a JavaBean instance. This instance can then be passed throughout the local application, or even be serialized and sent over the network, and clients can retrieve the model information from a local object without suffering any negative performance impact.

The DTO normally doesn't provide any business logic or validation; it just provides access to the properties of the bean. Some documentation on this pattern suggests that the bean should be immutable, to help reinforce that the object is local and that changes will not be reflected in the system. However, this can cause problems because the JavaBeans specification requires that all private properties have get and set methods. It is up to you to determine how best to handle the mutability of DTOs based on your requirements.

DTOs effectively are part of the model—they are just local, possibly immutable copies of the business objects. Within Struts applications, they are used by the view to deliver the model data that is rendered along with the static information in the page.

3) The ActionForm class is used to capture input data from an HTML form and transfer it to the Action class. Because users often enter invalid data, web applications need a way to store the input data temporarily so that it can be redisplayed when an error occurs. In this sense, the ActionForm class acts as a buffer to hold the state of the data the user entered while it is being validated. The ActionForm also acts as a "firewall" for your application in that it helps to keep suspect or invalid input out of your business tier until it has been scrutinized by the validation rules. Lastly, when data is returned from the business tier, a particular ActionForm can be populated and used by a JSP page to render the input fields for an HTML form. This allows more consistency for your HTML forms, as they always pull data from the ActionForm, not from different JavaBeans.

4) When parsing an HTML file, the browser determines how to process and handle the tags the file contains based on a set of standards. The purpose of JSP custom tags is to give the developer the ability to extend the set of tags that can be used inside a JSP page. With ordinary HTML tags, the browser contains the logic to process the tag and render the output. With JSP custom tags, the functionality exists in a special Java class called the tag handler.

5) Advantages of using custom tags

There are many benefits of using custom tags instead of scriptlets and Java code in your JSP pages:

· Tags are reusable, which saves precious development and testing time.

· Tags can be customized using attributes, either statically or dynamically.

· Tags have access to all of the objects available to the JSP page, including request, response, and output variables.

· Tags can be nested, which allows for more complex interactions within a JSP page.

· Tags simplify the readability of a JSP page.

6) Tag Libraries Included with Struts

The Struts framework provides a fairly rich set of framework components. It also includes a set of tag libraries that are designed to interact intimately with the rest of the framework. The custom tags provided by the Struts framework are grouped into four distinct libraries:

· HTML

· Bean

· Logic

· Template


About the Author

Chuck Cavaness is a graduate from Georgia Tech with degrees in computer engineering and computer science, has built Java-based enterprise systems in the healthcare, banking, and B2B sectors. Working at an Internet company to design and develop software architecture, Chuck has spent many frustrating hours figuring out the dos and the don'ts of web applications. With each enterprise system he's developed, Chuck has learned several valuable lessons about building "real-world" web applications, information that he's made available to developers who haven't had the opportunity to work on large systems.

Chuck is the co-author of Special Edition Using Java 1.3 and Special Edition Using EJB 2.0, both available from QUE.

No comments: