Java Reference
In-Depth Information
<jsp:include page="${url}"/>
Action Bean
MenuViewHelper
result
menu.jsp
Figure 7.4: Using a view helper
That's exactly what we need:
Download email_16/web/WEB-INF/jsp/common/layout_menu.jsp
<s:layout-component name="menu">
<s:url var="url" beanclass="stripesbook.action.MenuViewHelper"
prependContext="false">
<s:param name="currentSection" value="${currentSection}"/>
</s:url>
<jsp:include page="${url}"/>
</s:layout-component>
The URL is bound to the MenuViewHelper action bean. Its default event
handler forwards to menu.jsp , which displays the menu. The result is
put back in place of the <jsp:include> tag, as illustrated in Figure 7.4 .
Notice that we have to use a URL in the <jsp:include> tag because it's a
JSP tag, not a Stripes tag. But we can still continue to use action bean
class names instead of URLs. The <s:url> tag constructs the URL for
an action bean and stores it in a variable. We can then pass the value
to the <jsp:include> tag.
The prependContext= "false" attribute is necessary because <s:url>
prepends the application context to the URL by default, and the URL
passed to the
<jsp:include>
tag should not include the application
context.
With <jsp:useBean>, <s:useActionBean>, and the <s:url>/
<jsp:include>/action bean/JSP combination, we have powerful ways
of providing view helpers and building dynamic reusable layouts.
 
 
Search WWH ::




Custom Search