开发者

array as hidden variable

开发者 https://www.devze.com 2022-12-11 17:43 出处:网络
can array be used as hidden variable on jsp.....like I have a form i.e a simple java class,I want it to be as hidden variable can I do it..

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

Th开发者_JAVA百科anks in advance


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>  


just write multiple hidden elements with the same name en different values. struts will see that it is supposed to be an array


agree with BalusC in addition to that you can try following

adding [] at the end of the name , keeping name and property same and adding multiple values. for example

<html:hidden name="name1[]" property="status" value="value1" />
<html:hidden name="name1[]" property="status" value="value2" />
<html:hidden name="name1[]" property="status" value="value3" />
0

精彩评论

暂无评论...
验证码 换一张
取 消