Search code examples
struts

array as hidden variable


can array be used as hidden variable on struts.....like I have a form i.e a simple java class,I want it to be as hidden variable can I do it..

Thanks in advance


Solution

  • HTTP request parameters can only be strings. So you either have to convert it to a single string (maybe a commaseparated string?), but you need to convert it back yourself, or you have to use multiple hidden input values (all with the same name), which is generally a much better solution. In plain JSP/Servlet you can get them back using HttpServletRequest#getParameterValues() and Struts is smart enough to see that.

    <logic:iterate id="foo" name="bean" property="arrayOrList">  
        <html:hidden name="paramName" property="propertyName" indexed="true" />  
    </logic:iterate>