Java Reference
In-Depth Information
does not execute a request to the target; rather, it pulls the source code
into the JSP at the location of the directive:
Download email_19/web/WEB-INF/jsp/message_list.jsp
<s:form beanclass="stripesbook.action.MessageListActionBean">
<d:table ...>
<!-- ... -->
<d:column>
<s:checkbox name="selectedMessages" value="${message.id}"/>
</d:column>
<!-- ... -->
</d:table>
<c:if test="${not empty folder.messages}">
<div><s:errors field="selectedMessages"/></div>
<%@include file="/WEB-INF/jsp/common/message_action.jsp"%>
</c:if>
</s:form>
Download email_19/web/WEB-INF/jsp/message_details.jsp
<s:form beanclass="stripesbook.action.MessageListActionBean">
<%@include file="/WEB-INF/jsp/common/message_action.jsp"%>
<div>
<s:hidden name="selectedMessages"
value="${actionBean.message.id}"/>
</div>
</s:form>
Notice that in both cases the included code becomes nested within an
<s:form> tag. Indeed, the code from message_action.jsp is not valid on its
own, because it contains form input controls with no parent <s:form>
tag.
For the Message List page, the controls are included only if the folder is
not empty; it doesn't make sense to have controls for deleting or moving
messages when no messages are being displayed in the page!
For the Message Details page, the user does not have to select messages
because the controls apply to the currently displayed message. But we
do need a parameter to indicate this message; the <s:hidden> tag takes
care of that.
The great thing about doing this, besides reusing the message_action.jsp
code in two different contexts, is that we don't even need to change
anything in MessageListActionBean . Both forms submit the selectedMes-
sages parameter to a property of type List<Message> . The Message Details
page happens to submit only one value. The event handlers for delet-
ing and moving messages work the same either way: they iterate over
 
Search WWH ::




Custom Search