我正在使用userForm在struts 1中以我使用组合框提交值的形式提交用户属性但我的问题是当我提交或刷新表单时(即如果页面有一些验证问题) userForm中的选定值已消失..
<div class="row">
<label for="lbl-01"><bean:message key="registrationForm.contactState"/> <span class="formElementRequired">*</span></label>
<span id='ajaxContent'>
<html:select property="stateAddressId" styleId="stateAddressId" styleClass="lookSelect" onchange="showCityForState(this.value);" >
<html:option value="0"><bean:message key="tml.registration.option.selectState"/></html:option>
<c:if test="${stateList!=null}">
<logic:iterate id="stateObject" name="stateList">
<html:option value="${stateObject.id}"><bean:write name="stateObject" property="description"/></html:option>
</logic:iterate>
</c:if>
</html:select>
</span>
<logic:messagesPresent property="stateAddressId">
<font color="red"><html:errors property="stateAddressId" /></font>
</logic:messagesPresent>
</div>
<div class="row">
<label for="lbl-01"><bean:message key="registrationForm.contactCity"/> <span class="formElementRequired">*</span></label>
<span id='ajaxContentForCity'>
<html:select property="cityAddressId" styleId="cityAddressId" styleClass="lookSelect">
<html:option value="0"><bean:message key="tml.registration.option.selectCity"/></html:option>
<c:if test="${cityList!=null}">
<logic:iterate id="cityObject" name="cityList">
<html:option value="${cityObject.id}"><bean:write name="cityObject" property="description"/></html:option>
</logic:iterate>
</c:if>
</html:select>
</span>
<logic:messagesPresent property="cityAddressId">
<font color="red"><html:errors property="cityAddressId" /></font>
</logic:messagesPresent>
</div>
这是我设置值
的动作ReferenceService referenceService = (ReferenceService) GetSrvContxt.getInstance(request, "ReferenceService");
Vector<CityObject> cityVector = new Vector<CityObject>();
Vector<StateObject> stateVector = new Vector<StateObject>();
stateVector = referenceService.getStateList(registrationObject
.getContactObject().getContactCity().getContactState()
.getContactCountry().getId());
cityVector = referenceService.getCityDetails(registrationObject
.getContactObject().getContactCity().getContactState()
.getId());
request.setAttribute("stateList", stateVector);
request.setAttribute("cityList", cityVector);
答案 0 :(得分:1)
如果要保留请求之间的值,则需要将ActionForm实例的scope
更改为session
。默认情况下,它位于session
中。但也许它设置为request
,例如:
<?xml version="1.0" encoding="UTF-8"?>
<struts-config>
<form-beans>
<form-bean name="CustomerForm" type="mybank.example.CustomerForm" />
</form-beans>
<action-mappings>
<action path="/submitDetailForm"
type="mybank.example.CustomerAction"
name="CustomerForm"
scope="session"
validate="true"
input="/CustomerDetailForm.jsp">
<forward name="success" path="/ThankYou.jsp" redirect="true" />
<forward name="failure" path="/Failure.jsp" />
</action>
</action-mappings>
</struts-config>