struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maya menon <>
Subject Re: Tags in struts
Date Tue, 11 Jul 2006 14:50:22 GMT
Thanks Adam
  Implemented it and it worked.
  One quick question, when we use these tags, one of the options get selected by default.
How can we modify the tag so that NONE of the options get selected by default ?

Adam Gordon <> wrote:

Let's say your TestBean class has getFoo() and getBar() methods both 
which return Collection objects. If these objects are instances of 
LabelValueBean objects it's really easy, if they are not, I'd recommend 
converting them to these bean objects either in your bean class or in 
the action (though the latter could add additional overhead if not done 
correctly). Assume also that your TestBean class has getter and setter 
methods for ONE Foo and ONE Bar (say getOneFoo(), setOneFoo(String foo), 
getOneBar(), setOneBar(String bar).

In your Action's execute method (or a method called by execute(...)) 
type (assume testBean is an instance of the TestBean class and the 
getFoo() and getBar() methods return Collections of LabelValueBean objects):

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {


Collection fooCollection = testBean.getFoo();
Collection barCollection = testBean.getBar();

request.setAttribute("fooCollection", fooCollection); // 
"fooCollection" can be any text you want - i recommend using a final 
static reference instead of a hard-coded string.

request.setAttribute("barCollection", barCollection); // same 
comment applies


in your JSP, you would say:

your collection on the request -->



to render list boxes of your model data.

html:options knows that you have a Collection of objects (in this case 
LabelValueBean objects) that have the methods getValue() and 
getLabel(). Note that since these attributes are configurable, you can 
make the Collection a collection of any type of bean you want so long as 
all the beans in the collection have a getXXX() methods where XXX are 
the values of the attributes "property" and "labelProperty".

When your form is submitted, the setOneFoo(String) and setOneBar(String) 
methods will be called and set with the value of the "property" 
attribute. the "labelProperty" attribute dictates what is actually 
displayed to the user in the browser.

Let me know if you have any more questions.


Maya menon wrote:
> Thanks Adam.
> Yes, I have a bean lets say, Testbean with two Collections.
> I have to display the value of these Collections[has objects] in a
> select box in my JSP.
> Can you send me the sample code please ?
> Maya

To unsubscribe, e-mail:
For additional commands, e-mail:

Yahoo! Music Unlimited - Access over 1 million songs.Try it free. 
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message