aspose file tools*
The moose likes Struts and the fly likes html: options collection  in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html: options collection  in Struts" Watch "html: options collection  in Struts" New topic
Author

html: options collection in Struts

Priya Jotwani
Ranch Hand

Joined: Oct 30, 2002
Posts: 53
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

Joined: Feb 05, 2003
Posts: 4727

Sorry for not responding to the iterating question but I do have a suggestion.

Try:
<html ptions property="fundList"/>


A good workman is known by his tools.
Priya Jotwani
Ranch Hand

Joined: Oct 30, 2002
Posts: 53
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

Joined: Feb 05, 2003
Posts: 4727

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

Joined: Oct 30, 2002
Posts: 53
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

Joined: Feb 05, 2003
Posts: 4727

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

Joined: Oct 30, 2002
Posts: 53
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

Joined: Feb 05, 2003
Posts: 4727

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: html: options collection in Struts