📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
- Struts framework provides Tag libraries that allow you to build the view part of the MVC without embedding Java code directly within your application JSPs.
- Spring Framework provides some tags for form bindings, spring security tabs, evaluating errors, setting themes and outputting internationalized messages.
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<form:form method="post" modelAttribute="userForm" action="${userActionUrl}">
<form:input path="name" type="text" />
<!-- bind to user.name-->
<form:errors path="name" />
</form:form>
Table of contents |
---|
Problem |
Forces |
Solution |
Explanation |
Structure - Class Diagram, Sequence Diagram |
Participants and Responsibilities |
Implementation |
Consequences |
Applicability |
Real world examples |
References |
Problem
Forces
Solution
- A View delegates its processing responsibilities to its helper classes, implemented as POJOs, 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.
Structure
Class diagram
Sequence Diagram
Participants and Responsibilities
Implementation
<jsp:useBean id="welcomeHelper" scope="request"
class="corepatterns.util.WelcomeHelper" />
<HTML>
<BODY bgcolor="FFFFFF">
<c:if test = "${welcomeHelper.nameExists == true}">
<center>
<H3>
Welcome
<b>
<c:out value='${welcomeHelper.name}'/>
</b>
<br><br>
</H3>
</center>
</c:if>
<H4>
<center>Glad you are visiting our site!</center>
</H4>
</BODY>
</HTML>
public class MyTagHandler extends TagSupport {
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut(); //returns the instance of JspWriter
try {
out.print(Calendar.getInstance().getTime()); //printing date and time using JspWriter
} catch (Exception e) {
System.out.println(e);
}
return SKIP_BODY; //will not evaluate the body content of the tag
}
}
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>simple</short-name>
<uri>http://tomcat.apache.org/example-taglib</uri>
<tag>
<name>today</name>
<tag-class>com.javatpoint.sonoo.MyTagHandler</tag-class>
</tag>
</taglib>
<%@ taglib uri="WEB-INF/mytags.tld" prefix="m" %>
Current Date and Time is: <m:today/>
Consequences
- Improves application partitioning, reuse, and maintainability
- Improves role separation
- Eases testing
- Helper usage mirrors scriptlets
Real world examples
References
Related Presentation Tier Posts
- Intercepting Filter Design Pattern in Java
- Front Controller Design Pattern in Java
- Application Controller Design Pattern in Java
- View Helper Design Pattern in Java
- Composite View Design Pattern in Java
- Context Object Design Pattern in Java
Comments
Post a Comment
Leave Comment