我是这个框架的新手.在我的页面中,我有一个下拉列表和一个文本框.如果出现任何错误,则不再提供丢弃.如何解决这个问题.
struts.xml中:
<action name="*DropDown"
class="com.mmm.ehspreg2.web.action.DropdownListAction" method="{1}" />
<action name="addComment" method="add"
class="com.mmm.ehspreg2.web.action.product.CommentAction">
<result name="input" type="tiles">addComment</result>
<result name="error" type="tiles">addComment</result>
<result name="success" type="tiles">reloadList</result>
</action>
Run Code Online (Sandbox Code Playgroud)
页:
<s:form action="addComment" method="POST">
<s:action name="getDivisionsDropDown" id="actFetchDivisions" executeResult="true"></s:action>
<s:action name="getPropretyTypesDropDown" id="actFetchPropretyTypes" executeResult="true" ></s:action>
<table cellspacing="0" cellpadding="3" width="100%" border="0">
<tr>
<td class="error"><s:actionerror /><s:actionmessage /> <s:fielderror></s:fielderror></td>
</tr>
<tr>
<td class="bdyRecords"><s:label>
<s:text name="common.division" />
</s:label></td>
<td class="bdyRecords" style="width: 1px">:</td>
<td class="bdyRecords"><s:if
test="#actFetchDivisions.lstEntities.size()>0">
<s:select cssClass="drop" list="#actFetchDivisions.lstEntities"
cssStyle="width:200px" tooltip="divisionName"
id="select_division" listKey="id" name="comment.divisionId"
listValue="value"></s:select>
</s:if></td>
</tr>
<tr>
<td class="bdyRecords"><s:label>
<s:text name="common.propertytype" />
</s:label></td>
<td class="bdyRecords" style="width: 1px">:</td>
<td class="bdyRecords"><s:select cssClass="drop"
list="#actFetchPropretyTypes.lstEntities" cssStyle="width:200px"
tooltip="propertyTypeName" id="select_propertytype" listKey="id"
name="comment.propertyTypeId" listValue="value"></s:select></td>
</tr>
<tr>
<td class="bdyRecords"><s:label>
<s:text name="common.comment" />
</s:label></td>
<td class="bdyRecords" style="width: 1px">:</td>
<td class="bdyRecords"><s:textfield name="comment.commentText"
key="common.comment" size="50" maxlength="60" cssClass="textbxadd" /></td>
</tr>
</table>
</s:form>
Run Code Online (Sandbox Code Playgroud)
并通过CommentAction-validation.xml启用验证
你有几个我能想到的选择:
将下拉列表对象放在会话中
填充下拉列表时DropdownListAction,在会话中添加对它的引用.这样,如果验证失败,它将在您的JSP上可用.该解决方案的最后一步是在CommentAction成功执行后将其清除出会话.
行动链
您可以使用链条结果类型为你的input结果.这将允许您在验证错误时自动调用DropdownListAction.
<action name="addComment" method="add" class="com.mmm.ehspreg2.web.action.product.CommentAction">
<result name="input" type="chain">addCommentDropDown</result>
<result name="error" type="tiles">addComment</result>
<result name="success" type="tiles">reloadList</result>
</action>
Run Code Online (Sandbox Code Playgroud)
问题是,这可能会使输入字段的数量变得混乱.你必须试验它.