I wanted to declare an action in such a way that I could pass String
array of static parameter. I tried the below code:
The static parameters processed by the staticParams interceptor via the action config where the parameters are defined as Map<String,String>
.
For proper use of static parameters in the action config you should include reference to the interceptor staticParams
or use the defaultStack
.
<interceptor-ref name="staticParams">
<param name="parse">true</param>
<param name="overwrite">false</param>
</interceptor-ref>
You have also include setParams(Map<String,String> params)
in the action to the interceptor set the values of the params. Use different keys name1, name2, name3
in your case to retrieve the values of the map. You can also try overwrite
property (not documented) for the static params to not overwrite the value with the same key.
You can see the example of using static parameters in action config: Configure static parameter for Action class
try names[] instead names
<action name="saveRecord" class="saveRecordAction">
<result name="success" type="tiles">tiles:saveRecordSuccess</result>
<param name="names[]">name1</param>
<param name="names[]">name2</param>
<param name="names[]">name3</param>
</action>
AFAIK static parameters are converted to String, that why various interceptors (e.g. FileUploadInterceptor
) use static method commaDelimitedStringToSet
of TextParseUtil
to convert String
to Set<String>
. You can call this method inside setter for your property.
public void setNames(String name) {
mNames = TextParseUtil.commaDelimitedStringToSet(name);
}
The struts static param works like MAP. name been the KEY and value as VALUE. You can achieve your requirement by sending the values as comma separated and you can split it so that you can have your array there.
<param name="names">name1,name2,name3</param>
For more info on Static Parameters
Try this
<action name="saveRecord" class="saveRecordAction">
<result name="success" type="tiles">tiles:saveRecordSuccess</result>
<param name="names" value="new java.lang.String[]{'name1', 'name2', 'name3'}"></param>
</action>