Search code examples
arraysstringparametersstaticstruts2

Passing array of String as static param in Struts 2


I wanted to declare an action in such a way that I could pass String array of static parameter. I tried the below code:

<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>

I have a setter in my action class:

public void setNames(String[] name){
    mNames = name;
}

But I am only receiving one name which is the last one, "name3"

Is what I wanted possible? if yes, what is the correct way of doing it?


Solution

  • 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