I am experiencing some problems with the stripes layout. I will give a test case here:
Main Layout(main.jsp):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<s:layout-definition>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>{$title}</title>
</head>
<body>
<s:layout-component name="body"/>
</body>
</html>
</s:layout-definition>
Sub Layout which is extending the main(sub_main.jsp):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<s:layout-definition>
<s:layout-render name="/WEB-INF/jsp/common/main.jsp" title="${title}">
<s:layout-component name="body">
This is a test and this is from sub main
<div style="color: red; font-size: 5em;">
<s:layout-component name="subheader"/>
</div>
${body}
</s:layout-component>
</s:layout-render>
</s:layout-definition>
Now I am using the sub-main layout in the following code(test.jsp):
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<s:layout-render name="/WEB-INF/jsp/common/sub_main.jsp" title="Test Page">
<s:layout-component name="subheader">
This is from the sub header component
</s:layout-component>
<s:layout-component name="body">
This is from body
</s:layout-component>
</s:layout-render>
But in browser I am seeing the following:
This is a test and this is from sub main
This is from body
Instead of:
This is a test and this is from sub main
This is from the sub header component
This is from body
Above all the title is displayed as:
“$title”.
Please any body can give me a clue about what I am doing wrong ?
I noticed that subheader is defined within the body component of the sub_main.jsp defenition, I don’t think you can nest the component tags like that. You might want to try using a EL expression for the subheader instead (use: ${subheader}).
It’s maybe best to always use EL expressions instead of layout-component tags when rendering the contents of a layout-component and only use layout-components for defining the layout. You can’t use layout-components for rendering while nested in a layout-definition (this dual usage of the layout-component is a design fault of the library and leads to unnecessary confusion in my opinion).
See also the Nested Layouts section of the official Stripes documentation.