This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes declare arraylist as hidden field in the jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "declare arraylist as hidden field in the jsp" Watch "declare arraylist as hidden field in the jsp" New topic
Author

declare arraylist as hidden field in the jsp

Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Hello all,

I have a form which has an ArrayList of Customer objects.


CustomerForm{
priavte ArrayList custList;
//getter and setter methods
}

Customer{
private String fname;
private String lname;
//other variables and get set methods
}

Can some one let me know how to declare a hidden field for the custList in the struts jsp? Thanks a lot for your help.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can't. Anything you put in a hidden field must be a String (or at least an object that can be converted to a String). You can't put an ArrayList in a single hidden field.

If I were you, I'd just put this ArrayList in session scope. Then you can retrieve anywhere you need it. As long as you remove it when it's no longer needed, I doubt it would affect performance significantly.

If you insist on doing it the hard way, though, here's one possibility:

If all of the Customer properties are Strings, you could iterate through the ArrayList using <logic:iterate> and create hidden fields with indexed properties for each customer in the list. If you're unfamiliar with indexed properties, the links below will help you understand them:

http://struts.apache.org/1.2.x/faqs/indexedprops.html

http://wiki.apache.org/struts/StrutsCatalogLazyList
[ July 24, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Hari priya
Ranch Hand

Joined: Mar 11, 2004
Posts: 134
Thanks for your response Merrill.
I have set the arraylist in the session scope as you have mentioned.
Just wanted to know if there was a way to avoid it but it seems to be a more convenient way.

Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: declare arraylist as hidden field in the jsp
 
Similar Threads
declaring an arraylist or array type hidden variable in a form
private static
Displaying Tabular data using custom tags
Spring problem with Binding
sorting in bean objects