JavaServer Page

March 10, 2007

300 9.4.1 CHAPTER 9 Posing conditions with tags

Filed under: JSP Tag Libraries — webmaster @ 11:40 pm

Summary author or content developer from concerns over conditional logic so they may focus on presentation. A solution that bases itself on beans should look something like: ” property=”myQuery”> < %-- We are here if the query is true --%> < %--We are here if the query is false --%> This approach keeps the JSP syntax clean and straightforward, while enforcing a tidy separation of the business logic and presentation. The advantages of using Java- Beans to evaluate your conditions make it vastly superior to the previous approach, while satisfying all the requirements of supporting complex, real-world use. 9.5 Summary While it is feasible to implement an easy-to-use conditional tag, representing a condition (even a simple one) in a declarative manner is impossible. Therefore, unless you are going to implement your own condition specification language, you will be better off implementing your condition evaluation in a JavaBean, in which you can leverage all the power of the Java language to pre-process and evaluate your conditions. This approach leaves your tags with the sole task of checking the JavaBean s resulting values and including or excluding content based on the bean s exported values. Once you resolve to never attempt implementing a full-fledged condition specification language, implementing custom conditional tags becomes relatively easy. JSP is well adapted for conditional inclusion (as well as exclusion) of content using the Tag method call protocol and JSP will evaluate the conditioned content with no additional effort on your part. In the next chapter, we will look at how to build tags that support iteration, such as iterating over a list of JavaBean property values. We saw scriptlet code in chapter 8 that performed iteration; now we ll see how to eliminate these scriptlets and replace them with simple to use, flexible custom tags that perform the same functions.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting