Browse DevX
Sign up for e-mail newsletters from DevX


Mixing JSTL and JSF in Web Applications : Page 4

Even though the JavaServer Pages Standard Tag Library (JSTL) and the newer JavaServer Faces (JSF) technology are very different, they're not totally incompatible. Find out how and when you might want to consider mixing the two to achieve a blend that's smoother than either one alone.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Completing the Application
When the user accepts a loan scenario, the application displays the screen shown in Figure 4.
Figure 4: Final Results Screen: Here's a sample of the text shown on the final results screen, after a user accepts the loan scenario.
The source code for the screen shown is in thankYou.jsp. This screen uses JSTL only. It does not provide for any user interaction. It only displays results. This is perfect for JSTL. There's no advantage gained by using JSF for such static screens unless you're creating a brand new application. JSTL gets access to the JSF managed bean by treating it as a session object. For example, the following code accesses the JSF defined MortgageLoanAccount managed bean as a session object and invokes the getter method to retrieve the principal attribute on its acceptedScenario attribute.

The code to accomplish the same thing in JSF is:

<h:output_text value="#{MortgageLoanAccount.acceptedScenario.principal}"/>

You'll find the complete source code in the downloadable source code in the file mortgageCalculator.zip.

JSTL's SQL tags were intended to be used for prototyping Web applications, and aren't really appropriate for building modular MVC applications. Hence, they were not included in this article. They can, if necessary, be used to display any content other than form field values on Web pages of a JSF application.

JSTL's XML tags can be used to transform XML data using XSL. To maintain a clean coexistence of JSF and JSTL, you should use these tags to render content other than a JSF form. For example, visually rendering printable documents originating from an XML source is a perfect way to use the tags. Any other direct parsing of XML data by a JSTL tag violates MVC architecture best practices.

Interweaving JSTL and JSF tags will produce a fiasco, and I don't recommend that. But as long as you maintain some separation between them, you will be okay. What you've seen in this article are some possibilities to get you thinking along the lines of how to use both and still maintain that separation. This article is not comprehensive by any means. It is a preliminary collection of ideas prior to the advent of mature JSF tools—a maturation which may throw a lot of twists into this equation.

JSF is still new; few developers have used it to create business applications yet. In the near future, as tool support for this technology emerges, JSF will attract a lot more attention. After the dust settles, performance issues related to JSF will surface. JSF's limitations with respect to validation and peaceful coexistence with other current Java technologies will draw more attention. It will be interesting to see which technologies will blend together into a meaningful end result. JSF is here to stay, mainly because of its standardization, while JSTL's simplicity is its strongest selling point. There's very little overlap between JSF and JSTL, so it's quite possible for the two technologies to coexist, as explained in this article. The strategies outlined here provide clean options for application development using the best of both worlds.

Subbu Ramanathan is a senior consultant/technical architect at Spider Logic. He has extensive object-oriented software design and development experience. As a professional trainer, he frequently offers seminars on a variety of software development topics.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date