• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html: options collection in Struts

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I want to populate my listbox from the field called 'fundlist' in my ActionForm(named as myForm).The getFundlist() returns an ArrayList of funds.Please validate if the same should be implemented in the foll. way

I understand that if i'm not using the Struts <html ptions collection> tag, I would have been iterating through my Arraylist to populate the Listbox. How would it be done using the above code ?

Thanks in Advance,
Priya
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for not responding to the iterating question but I do have a suggestion.

Try:
<html ptions property="fundList"/>
 
Priya Jotwani
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marc,

Thanks for your reply. But i got even more confused now.
Why should I not use 'collection' of <html ptions> ?

TIA,
Priya
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because if my suggestion works, you have gone from 2 attributes to 1 and from 1 scriptlet to 0. This makes things a bit more elegant.

The collection and name attributes are really only necessary if you are accessing a collection NOT in the ActionForm already associated with the page.
 
Priya Jotwani
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marc, can you please elaborate more on the implementation ?
I should be using the normal iterator thing to iterate through my fundlist and then populate the listbox ?

TIA,
Priya
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should look like this:


ActionForm should have
public String getSelectedFund()
public void setSelectedFund(String fund)
and
public List getFundList()

iterator is not necessary. Struts will use its magic for prepopulation and preselection if you do the above.
 
Priya Jotwani
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marc for being so patient
But my getSelectedFund() returns an ArrayList(and not String) which I want to populate in the Listbox.
If it was returning a String, i understand that the String value would have got populated in the Listbox but am worried because it returns me multiple funds

TIA,
Priya
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the name getSelectedFund would imply that it is returning only the string that represents the value of the item selected. If nothing is selected, it should return null.

And since I made that method up, I somehow doubt that you already had it, let alone that you could claim that it returns a List instead of a String.

The only method you showed to have was getFundList() which DOES return a List. I included that one as well in my elaborated implementation.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic