I noticed in your <html:select> attributes that you didn't specify "multiple" as an 
attribute.  If it is just a single select, there is a "value" attribute that can be 
set that is a property of the <html:select> tag. If the property of "value" in the 
html:select tag matches the property of "property" in the html:options tag, then it 
will display it as selected.

The method I talk about below uses a regular ActionForm and not the DynaActionForm, 
but it still applies.  If you choose not to use the "value" attribute of the 
<html:select> tag, you can also use the bean that is associated with the <html:form> 
that you are in.  In your action.execute(), if you set your bean variable that matches 
"property" of the <html:select> (should be a String[] for multiple) and in it list the 
"property"'s from the <html:option> that you want selected, they will be displayed as 
selected.  Below is an example:
<code>
----- the jsp ----
<html:select property="callStatus" styleClass="textBox" multiple="true" size="3">
     <html:options collection="CallStatusList" property="callStatusCode" 
labelProperty="callStatusDescription" />
</html:select>

-- in the action.execute() --
ClaimReportingForm claimReportingForm = (ClaimReportingForm) form;
String[] selected = {"ALL","D"};
claimReportingForm.setCallStatus(selected);

</code>
So, now when ever the page is displayed, any of my callStatusCode that matches "ALL" 
or "D", will be selected.



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

>Steve, 
>Thank you VERY much.  I will be sure to take a look; half the battle is finding 
>examples. 
>
>Natalie 
>
>Steve Raeburn wrote: 
>
>Natalie, 
>
>If it would help, I've put together an example application 
(http://www.ninsky.com/struts) that shows most of the basic tags in action. 
It actually came about after a discussion about options examples, so there 
may be something you could use. 
>
>It's available as a WAR file that you can deploy directly to your servlet 
container and includes viewable source so you can cut-and-paste any examples 
that might do what you need. 
>
>Another useful source of examples is the excercise-taglib application which 
is included in the struts distribution. It's got more comprehensive coverage 
of the tags than mine but is designed to test the tags rather than be easy 
to understand for someone new to Struts. 
>
>HTH 
>
>Steve 
>
> -----Original Message----- 
> From: Rassmann, Natalie D [mailto:[EMAIL PROTECTED] 
> Sent: June 23, 2003 11:43 AM 
> To: Struts Users Mailing List 
> Subject: Re: html:option - is there a selected option attribute? 
> 
> 
> Wendy, 
> 
> You have been very helpful.  This is my first STRUTS app and I seem to 
> stumble the most on getting these tags to work.  I have not found any real 
> documentation examples to help me.  At any rate, I tried to use 
> the options 
> collection tag and I had no success.  It was one error after another.  I 
> finally got the lists to display as a drop down using the JSTL 
> tag forEach. 
> 
> 
> This is what my code looked like when I was trying to use the options 
> collection tag: 
> 
> 
>  <html-el:select name="reviewRecordForm" property="csci.options"> 
>      <html-el:options collection="${reviewRecordForm.map.csci}" 
> property="optionId" labelProperty="optionLabel"/> 
>   </html-el:select> 
> 
> 
> After reading what you wrote, I think I should try the following to get it 
> to work: 
> 
> 
>  <html-el:select name="reviewRecordForm" property="csci"> 
>      <html-el:options 
> collection="${reviewRecordForm.map.csci.options}"property="optionId" 
> labelProperty="optionLabel"/> 
>   </html-el:select> 
> 
> 
> csci is another property in my form bean which is the same type as 
> baseline.....  In the properties field of the select tag I used the 
> collection instead of the actual form bean property.  I think 
> maybe this was 
> my problem.  I am going to try it and see what happens. 
> 
> 
> Do you think I am on the right track?? 
> 
> 
> Thanks for your help, 
> 
> 
> Natalie 
> 
> 
> Wendy Smoak wrote: 
> 
> 
> Natalie wrote: 
> > In my Action's execute method, I do a beanutils.copyProperties 
> to copy the 
> 
> 
> 
> > dto (data from DB) into my form.  So, my form bean property is 
> already set 
> 
> 
> 
> > to the list. This list is used to build the select list drop 
> down box in 
> my jsp. 
> 
> 
> The entire contents of the drop down is a different thing than the single 
> item from that list that the user has selected.  I don't store 
> the lists of 
> items in my Form bean, but YMMV. 
> 
> 
> You don't have to do the iteration with c:forEach, the select tag 
> will do it 
> 
> for you. 
> 
> 
> Here's one of mine: 
> <html-el:select property="purpose"> 
>  <html-el:options collection="reminderPurposes" property="key" 
> labelProperty="value"/> 
> </html-el:select> 
> 
> 
> Where 'reminderPurposes' is a Collection sitting in Application scope. 
> 
> 
> If I wanted to "pre-select" a certain item, I might (in the 
> Action's execute 
> 
> method) do: 
> ( (DynaActionForm) form ).set( "purpose", "GI" ); 
> 
> 
> Instead, I just do this: 
>    BeanUtils.copyProperties( dvForm, contact ); 
> and since the DTO and the form both have a 'purpose' property, the value 
> gets copied from the DTO (contact in this case) to the form. 
> 
> 
> You ask what you're supposed to set 'baseline' to.  I thought you were 
> originally asking how to pre-select a certain value before the form is 
> displayed for the first time.  If you don't have a value in mind, 
> then don't 
> 
> set it to anything. 
> 
> 
> However, most of the problem seems to be that you're working too hard... 
> Struts handles most of this, the iteration over a Collection, 
> pre-selecting 
> the right item, magically behind the scenes, and you don't have to do 
> anything. 
> 
> 
> -- 
> Wendy Smoak 
> Applications Systems Analyst, Sr. 
> Public Affairs, Information Resources Management 
> Arizona State University, Tempe AZ 



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

Reply via email to