The View Helper pattern

The View Helper pattern separates the static view, such as JSP, from the processing of the business model data. The View Helper pattern is used in the presentation layer by adapting the model data and the View components. The View Helper can format the model data according to the business requirement, but it cannot generate model data for the business. The following diagram illustrates the View Helper pattern:

We know that View is the a static and formatted component of the MVC pattern, but sometimes, we need some business processing the presentation layer. If you are using JSPs, then you could use a scriptlet for the business processing at the the view layer, but using a scriptlet is not a best practice, because it promotes tight coupling between the view and business logic. But some View Helper classes based on the View Helper pattern take over that responsibility of business processing at the presentation layer. Some of the technologies based on the View Helper pattern areas follows:

  • The JavaBeans View helper
  • The tag LibraryView helper
    • Using JSTL tags
    • Using spring tags
    • Using third-party tag Library

The following tag libraries are used in our web application in this chapter:

    <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> 
    <c:if test="${not empty account }"> 
     .... 
     ....         
    </c:if> 
 
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
    <form:form method="post" commandName="account"> 
    .... 
    ... 
   </form:form> 

As you can see in the preceding code, I have used the JSTL tag library for the check not empty account in the model, and the Spring tag library to create the open account form in the web application.

In the next section, you'll learn about the Composite View pattern, and how Spring MVC supports it to implement it in the web application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset