我已经查看过此处的帖子,我似乎无法找到我的问题如何设置。我的控件确实在初始加载时填充,但在验证失败时不填充。如果我转到索引页面它加载正常,如果我去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"));
}
的index.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>
答案 0 :(得分:0)
input
。相反,您已经为success
结果编写了规则。如果真实代码是github上的代码,那么只有在验证失败的情况下,您的代码才会起作用...请仔细检查您的设置。请注意,您不需要在Action中实例化另一个Action;使用Pojo。