File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html: options collection in Struts

 
Priya Jotwani
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic