JavaServer Page

March 10, 2007

300 9.4.1 CHAPTER 9 Posing conditions with tags

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

300 9.4.1 CHAPTER 9 Posing conditions with tags Supporting complex conditions with a condition language Inventing a condition language is a reasonable approach to supporting conditions; in fact, we had a very simple type of condition language in our TestTag. Why not improve on it? For example, assume that our condition can look like this: Some JSP code … One resounding benefit to creating a new condition language is that you can make it as complex and as powerful as you desire. Since you ll have total control over the language, you can support as many operands, functions, or comparisons as you desire by extending it. At this level, defining our own conditional language seems like a good approach. There are, however, several notable drawbacks. Drawbacks of complex condition languages By designing your own condition language you can easily support complicated queries; however, to do so you need first to develop a complex parsing mechanism and then implement all the functionality the language supports, including utility functions (such as Trim() in the previous example). This can prove to be a substantial undertaking. Furthermore, once you are finished with new language implementation, you will have to teach it to whomever will be using it. And if that were not enough, you will probably need to provide mechanisms for JSP authors to debug their conditions. Will you provide an IDE to let developers step into your proprietary implementation? After this analysis, it becomes clear that in order to build a debuggable, feature-rich condition language (and the code to support it) you end up building a system similar to commercial products like ColdFusion. Unless you are planning on selling this tag library commercially and for a nifty price, the effort required to support complex conditions this way is not worth it. There must be a better way to solve the problem with a more standard condition language and less effort. One alternative, it turns out, is to use Java. Supporting complex conditions with JavaBeans JSP already supports Java. To take advantage of this, let s place all our conditions in a JavaBean and query the values of that bean s properties. The JavaBean now contains the complicated Java code that performs the condition, and can leverage all the natural features of the Java language. This approach also makes it very easy to debug the code (since you can simply use your favorite Java IDE), and prevents us from supporting any complex parsing or training JSP authors in our own proprietary language. Though this method requires you to write the beans that contain the conditional logic, this will simply be handled by the business logic developer, freeing the JSP

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