Using your example,

<html:select property="foo">
   <html:options collection="bar" property="name"/> 
</html:select>

The short answer is that the value that will be shown selected is the value from the 
collection that matches the value returned by getFoo() on the form-bean.  So if foo is 
'apple' and the collection contains 'apple' then that item will be shown as selected.  

What I was saying was if want to always have the first item in the list shown as 
selected you *could* try to leave the value of foo blank.  The sure-fire way is to set 
the value of foo to be the value of the first item in the collection.

I should also point out that the usage you have shown above doesn't seem to be 
correct.  I have always used it as follows

<html:select property="foo">
   <html:options collection="bar" 
           property="name"
      labelProperty="label"/> 
</html:select>

If you refer to the docs for <html:options> it reads (for the "collection" attribute):

Name of the JSP bean (in some scope) which is itself a Collection of other beans, each 
of which has properties named by the "property" and "labelProperty" attributes that 
are used to retrieve the value and label for each option, respectively. (RT EXPR) 

Hope that gets you going in the right direction.

Sri


-----Original Message-----
From: Ray Madigan [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 25, 2003 2:49 PM
To: Struts Users Mailing List
Subject: RE: Searching the Archive


I thought <html:select worked as follows:

property is the name of the request parameter where the answer is placed. name is the 
name of a bean that is consulted to set the selection value is the property of the 
bean identified by name to get the comparison

if I use
<html:select property="foo">
   <html:options collection="bar" property="name"/> </html:select>

will create a select with the values from the bean in attribute bar with value getName 
( )

But select comes up with no selection?

I just want the first item.  I don't want to have to set an attribute with the first 
element of the collection in my action class.

I will, but - i don't wanna!



-----Original Message-----
From: Sri Sankaran [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 25, 2003 11:36 AM
To: Struts Users Mailing List
Subject: RE: Searching the Archive


Are you asking how to make the default selection of an <html:select> the first option? 
 As you have pointed out you can set the property attribute of the <html:select> equal 
the value of the first option.

Alternatively, *I think* if you leave the property blank, HTML rules indicate that the 
first item be shown.  Note that in the case of a <html:select> with multiple 
selections, this *may not* result in any item being selected; in this case your only 
choice to set the property attribute of the <html:select>.

Sorry if I completely misunderstood your question.

Sri

-----Original Message-----
From: Ray Madigan [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 25, 2003 2:22 PM
To: Struts Users Mailing List
Subject: Searching the Archive


I was searching the Struts Archive and got the following error:

javax.servlet.ServletException: Error initializing Velocity: 
java.lang.ArrayIndexOutOfBoundsException
        at org.apache.velocity.servlet.VelocityServlet.initVelocity(VelocityServlet.jav
a:236)

I was trying to locate some help in <html:select.
I only want to select the first element - It seems like I need an object with a 
property that will be used to match the property used in the <options tag.  This seems 
like a bunch of work to simply select the first element of the options list.

Thanks
Ray Madigan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to