Abhi
Abhi

Reputation: 384

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

Upvotes: 0

Views: 5277

Answers (3)

atom217
atom217

Reputation: 987

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

Upvotes: 0

BalusC
BalusC

Reputation: 1109362

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>  

Upvotes: 4

Salandur
Salandur

Reputation: 6453

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

Upvotes: 0

Related Questions