Showing posts with label JSTL. Show all posts
Showing posts with label JSTL. Show all posts

Create custom JSTL and use it as wrapper for other JSPs (code)

Create custom tags in JSTL and use them as templates

File structure in folders:
WEB-INF
 ----jsps
 --------home.jsp
 --------createproduct.jsp
 ----tags
 --------pagewrapper.tag
 ----template
 --------product.jsp

pagewrapper.tag  (Place for static content, general for all pages)

<%@ tag description="Page Wrapper Tag" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ attribute name="title" fragment="true" %>
<%@ attribute name="header" fragment="true" %>
            <jsp:invoke fragment="title"/>
    
    
    


     

Home </body> </html>

home.jsp (It has unique attributes of home page such as "title" and "header")

<%@ page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
    
    
        Page title
    
    
        App name
    
    
        
    


createproduct.jsp (It includes product.jsp that are general for some pages)

<%@ page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
    
        Create product
    
    
        Create product
    
  
      
  


product.jsp
<%@ page isELIgnored="false" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>


    
Product name: