I\'m passing some parameters to an action class implementing ModelDriven
through a query-string.
No array problem is involved here (even if it seems like that): this kind of exception means that Struts can't find a Setter for your parameter:
From ParametersInterceptor documentation:
Warning on missing parameters
When there is no setter for given parameter name, a warning message like below will be logged in devMode:
SEVERE: Developer Notification (set struts.devMode to false to disable this message): Unexpected Exception caught setting 'search' on 'class demo.ItemSearchAction: Error setting expression 'search' with value ['search', ] Error setting expression 'search' with value ['search', ] - [unknown location] at com.opensymphony.xwork2.ognl.OgnlValueStack.handleRuntimeException(OgnlValueStack.java:201) at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:178) at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:152)
Thus is expected behaviour to allow developer to spot missing setter or typo in either parameter name or setter.
You can easily reproduce this error by putting an element in JSP that does not exist in the Action.
Since your properties exist (with their Setters) in the Model, and you are using ModelDriven
and paramsPrepareParamsStack
, what I think is going on is:
ModelDriven Interceptor
is delegated to handle the Model object;Parameters Interceptor
, ModelDriven Interceptor
has not run yet; But if this is true, then you should NOT be able to retrieve those parameters in the prepare()
method (that is the reason you are using this stack...):
please try, and post here the result.
The first thing that comes to my mind to resolve this issue, is to place the ModelDriven Interceptor
before the first Parameters Interceptor
(by either copying it, or by moving it, I'm not sure which kind of side effect, if any, it could produce in both cases, you should again try and reporting it here).
Then define the following stack, and use it.
<interceptor-stack name="modelParamsPrepareParamsStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<!-- NEW ModelDriven Position -->
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="params">
<param name="excludeParams">^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<!-- OLD ModelDriven Position -->
<!--interceptor-ref name="modelDriven"/-->
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">^dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,^parameters\..*,^action:.*,^method:.*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
Hope that helps.
In the code that you have given, I can't find the declaration of the Transporter Class.
So I guess that maybe it is because your Transpoter class has more parameters than 2, not just id and name.
In fact, this error message always occurred on the situation I mentioned.
To solve this problem, you can define a data transport object(DTO) which only has 2 attributes,id and name. Use this DTO to accept parameters from the jsp, and then pass the attributes value to the Transporter object.
I see this problems in 2019, and offer a solution, hoping that it can be of use by others in the future.