----- Original Message -----

From: "Jan Aren�" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 21, 2003 1:31 PM
Subject: Re: Struts question


> Thanks for your response, I will get right on it... And ttry to figure
> it out...

> Have some questions though...

No problem.

> I get the idea of the listener, but if you populate it with stuff from a
> database, this would be wrong I guess, since this collection never
> updates (except when you restart you application). So what you do here
> is to create a constant (based on stuff when the aplication starts)...
> Or did I get i wrong?

No, of course - but IIRC I said 'static lists', didn't I? :-)

> If i'm not going to do the listner "thing", since my list must refresh
> from database once and awile... Where do I put the Colloction creating
> code, say this:

> Collection coll = new ArrayList();
> for(int i = 0; i < 10; i++) {
> b = new LabelValueBean("1",1);
> coll.add(b);
> }
> request.setAttribute("MY_LIST", coll);

This depends. If it's a request scope thing that should
be updated on each request, put it in an Action that
puts the Collection in request scope and then forward
to the input page. If it's a per-user thing, I usually
put the Collection in session scope (session.setAttribute())
when the session is initially created, often right after
successful authentication. But you can always add the
list at a later stage or update | replace it whenever it
seems fitting ;-)

> And when I do this on my jsp-page:

> <html:select property="selectedValue" value="-1">
> <html:options collection="MY_LIST" property="value"
> labelProperty="label" />
> </html:select>

> Do "value" and "label" represent a getValue() and getLabel() function in
> LabelValueBean?

Exactly. LabelValueBean is basically a 'convenience' Value
Object that is just there because it's used so often. But you
could take any other Bean as well. Then you would have to
specify which properties should be used for the <option>s
value and description. IIRC you can even omit specifying the
property and labelProperty attributes if the Bean accessors
are named "label" rsp. "value", but I never actually tried.

> Thanks again for your response, cleared up alot in my head :D

/Jan

Cheers,
-- Chris (SCPJ2)

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to