Design Pattern

View Helper Design Pattern – Core J2EE Patterns

View Helper Design Pattern separates the static view such as JSPs 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. View Helper can format the model data according to the your business requirement, but it can not generate model data for the business.

View Helper Design Pattern

In order to adapt model data into the presentation layer of the application, the view helper pattern is used, which specifies the use of helpers for such implementation. The presentation layer, generally, have a number of JavaServer (JSP) Pages. In order to present content to the user, these pages contain HTML and images. The problem takes roots when the JSP pages are required to display dynamic content which is stored within the model. The embedding of Java code needs to be avoided in order to display model data by these pages. Instead if that, helpers must be employed to resolve the issue. There are certain choices that the developer has, they can add JDP scriplets by embedding Java code, they can use EL or they can add helpers in order to extract the data for them. It makes more sense to employ a number of helpers in order to adapt the model to the presentation that it does if the java code is cluttered with the presentation code. This helps in keeping the presentation code and the business logic separated.

Spring 5 Design Pattern Book

You could purchase my Spring 5 book that is with title name “Spring 5 Design Patterns“. This book is available on the Amazon and Packt publisher website. Learn various design patterns and best practices in Spring 5 and use them to solve common design problems. You could use author discount to purchase this book by using code- “AUTHDIS40“.

Class Diagram for View Helper

Let’s see the following class diagram for the view helper pattern.


A View delegates its processing responsibilities to its helper classes, implemented as JavaBean, custom tags, or tag files. Helpers serve as adapters between the view and the model, and perform processing related to formatting logic, such as generating an HTML table.

The view helpers make it a lot easier for the page developers to develop the presentation layer when they replace it by the helper, which are also simpler to use. The developers, however, need to publish a catalog of the helpers along with the description as to how to use them, in order to accomplish this. The problem occurs when the application designer is not ready to give them page developers a model for the helpers, with which they are supposed to work, but the page designer has already developed the respective pages. In order to resolve this problem, the developers can code a set of dummy data into the helper, when there is no model present. An alternative method, to address this problem can be to provide a dummy model with which to work. Whichever of the methods is chosen, the age developer will not have to wait for the developers. The view helper caters certain issues and improves certain features of the application. It gives the developers, improved application portioning, improved re-usability and maintainability. It also improves the role separation, like in between the presentation code and business logic.

It eases the testing process for the page developers. The use of helpers mirrors the scriplets, it completely functions like one and can be put to advantage like one too.

Example for View Helper Pattern

As we know that the View is the static and formatted component of the MVC pattern, but some we need some business processing the presentation layer. If you are using JSPs then you could use scriptlet for the business processing at the view layer but using scriptlet is not best practice because it promotes the tight coupling between the View and Business Logic. But some View Helper classes based on the View Helper pattern take that responsibilities of the Business Processing at the Presentation layer. Some of the technologies based on the View Helper pattern are below:

  • JavaBeans View Helper
  • Tag LibraryView Helper
  • Using JSTL Tags
  • Using Spring Tags
  • Using Third-Party Tag Library
Previous
Next
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

3 years ago