我已经查看了这里以前的帖子,我似乎找不到我的设置问题。我的控件确实会在初始加载时填充,但不会在验证失败时填充。如果我转到索引页面,它加载正常,如果我转到 struts xml 文件中定义的操作,它很好。唯一的问题是在验证重新加载之后。
来自 jsp 文件的相关部分。
<s:form action="CreateReq" method="post" validation="true" theme="simple">
<s:select name="measurementList"
list="measurementList"
listKey="Name" listValue="Id"
class="quantitydropdown">
</s:select>
</s:form>
验证类
@Override
public void prepare(){
prepareRequisitionInformation();
}
public String prepareRequisitionInformation(){
PrepareCreateRequisitionAction prepare = new PrepareCreateRequisitionAction();
setMeasurementList(prepare.getMeasurementList());
loadAwaitingRequisitions();
return success;
}
PrepareCreateRequisitionAction 类
public ArrayList<Measurement> getMeasurementList() {
if (measurementList==null || measurementList.isEmpty()){
this.createMeasurementList();
}
return measurementList;
}
private void createMeasurementList() {
measurementList = new ArrayList<Measurement>();
measurementList.add(new Measurement("Bag", "Bag"));
measurementList.add(new Measurement("Box", "Box"));
measurementList.add(new Measurement("Cubic decimeter", "Cubic decimeter"));
}
索引.jsp
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=CreateReq.action">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>HTML 5 with Struts 2</title>
</head>
struts.xml
<action name="CreateReq" method="execute" class="com.te.sss.action.CreateRequisitionAction">
<result name="success">/success.jsp</result>
<result name="input">/createRequisition.jsp</result>
</action>