This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

declare arraylist as hidden field in the jsp

 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic