The issue is related to the ModelDriven
and Struts 2.3.16. Since the behavior of the params
interceptor changed to access parameters passed to the action requires to configure acceptParamNames
list to use with ModelDriven
action. If acceptParamNames
list is empty, it works by default accepting params via default pattern. Suppose we have a
ModelDriven
action:
@Namespace("/modelDriven")
public class ModelDrivenAction extends ActionSupport implements ModelDriven {
private Gangster model = new Gangster();
private String name; //getter and setter
public Object getModel() {
return model;
}
@Actions({
@Action(value="modelDriven", results=@Result(location = "/modelDriven/modelDriven.jsp")),
@Action(value="modelDrivenResult", results=@Result(location = "/modelDriven/modelDrivenResult.jsp"))
})
public String execute() throws Exception {
model.setName(name);
return SUCCESS;
}
}
the model:
public class Gangster {
private String name; //getter and setter
}
modelDriven.jsp:
<s:form id="modelDrivenForm" action="modelDrivenResult" method="POST" namespace="/modelDriven">
<s:textfield
label="Gangster Name"
name="[1].name"/>
<sj:submit cssClass="btn btn-primary" executeScripts="true" targets="div1"/>
</s:form>
<div id="div1"/>
modelDrivenResult.jsp:
<s:label
label="Gangster Name"
name="name"/><br/>
In the action execute
method we are getting parameter name
which should be populated by the params
interceptor and initializing the model property to display it in the result. But the problem is the parameter is not populated. How to get parameter name
being populated by the params interceptor, so the action could display the value?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…