I'm passing some parameters to an action class implementing ModelDriven<Transporter>
through a query-string.
<s:form namespace="/admin_side" action="Test" id="dataForm" name="dataForm">
<s:url id="editURL" action="EditTest" escapeAmp="false">
<s:param name="transporterId" value="1"/>
<s:param name="transporterName" value="'DHL'"/>
</s:url>
<s:a href="%{editURL}">Click</s:a>
</s:form>
The action class is as follows.
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value = "struts-default")
public final class TestAction extends ActionSupport
implements Serializable, Preparable, ModelDriven<Transporter>
{
private static final long serialVersionUID = 1L;
private Transporter transporter = new Transporter();
@Action(value = "Test",
results = {
@Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
interceptorRefs = {
@InterceptorRef(value = "paramsPrepareParamsStack",
params = {"params.acceptParamNames", "transporterId, transporterName"})})
public String load() throws Exception {
return ActionSupport.SUCCESS;
}
@Action(value = "EditTest",
results = {
@Result(name = ActionSupport.SUCCESS, location = "Test.jsp"),
@Result(name = ActionSupport.INPUT, location = "Test.jsp")},
interceptorRefs = {
@InterceptorRef(value = "paramsPrepareParamsStack",
params = {"params.acceptParamNames", "transporterId, transporterName"})})
public String edit() {
System.out.println(transporter.getTransporterId()
+ " : " + transporter.getTransporterName());
return ActionSupport.SUCCESS;
}
@Override
public Transporter getModel() {
return transporter;
}
@Override
public void prepare() throws Exception {}
}
The server terminal displays the following messages.
Jan 09, 2014 4:06:32 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'transporterId' on 'class actions.TestAction: Error setting expression 'transporterId' with value ['1', ]
Jan 09, 2014 4:06:32 PM com.opensymphony.xwork2.interceptor.ParametersInterceptor error
SEVERE: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'transporterName' on 'class actions.TestAction: Error setting expression 'transporterName' with value ['DHL', ]
Even though the log level is SEVERE
, the values of these parameters are available in the action class as
System.out.println(transporter.getTransporterId()
+ " : " + transporter.getTransporterName());
in the edit()
method.
If paramsPrepareParamsStack
is replaced by defaultStack
then, these messages disappear.
Expressions like ['DHL', ]
indicate an array. transporterId
and transporterName
in the model are, however of type Long
and String
respectively.
What am I doing wrong?
paramsPrepareParamsStack
along withModelDriven<T extends Object>
, field/property values in the model were not available in theprepare()
method. Using this stack, those messages vanished into thin air, model values are also available in theprepare()
method. – Quamash