You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jpiser <jp...@averoinc.com> on 2008/02/12 15:25:42 UTC

How to pre-select options in
I am new to Struts 2 and if anyone can help me out I would greatly appreciate
it. 

I am populating a select box with a list of job titles. After posting the
form I want to the list to remember the previous selection. (Ridiculously
simple stuff right?) But, I am missing something because after the form is
submitted the list is always reset. This is the code I have for the select
box:

<s:select label="Title"
       name="title"
	   tooltip="Please select your job title"
       headerKey="0" 
	   headerValue="Select Title"      
	   listValue="titleName"
	   listKey="name" 
	   list="titleList"
       value="selectedTitle"
       required="true" />

titleList is an ArrayList and it populates the options fine. I am
implementing the 'preparable" interface  in my action bean and populating
titleList in the prepare() method.

Thanks for any help you can give -
-- 
View this message in context: http://www.nabble.com/How-to-pre-select-options-in-%3Cs%3Aselect-tag---tp15434034p15434034.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to pre-select options in Posted by Laurie Harper <la...@holoweb.net>.
jpiser wrote:
> I am new to Struts 2 and if anyone can help me out I would greatly appreciate
> it. 
> 
> I am populating a select box with a list of job titles. After posting the
> form I want to the list to remember the previous selection. (Ridiculously
> simple stuff right?) But, I am missing something because after the form is
> submitted the list is always reset. This is the code I have for the select
> box:
> 
> <s:select label="Title"
>        name="title"
> 	   tooltip="Please select your job title"
>        headerKey="0" 
> 	   headerValue="Select Title"      
> 	   listValue="titleName"
> 	   listKey="name" 
> 	   list="titleList"
>        value="selectedTitle"
>        required="true" />
> 
> titleList is an ArrayList and it populates the options fine. I am
> implementing the 'preparable" interface  in my action bean and populating
> titleList in the prepare() method.

You have name="title" so you would need a setTitle() method on your 
action to capture the selected value. However, you have 
value="selectedTitle" so you're telling the tag to read the value from 
one property and store it to another. You probably want to remove the 
value attribute and use name="selectedTitle", with a setSelectedTitle() 
method. You only need value= if you explicitly want to get a value from 
somewhere other than the property the input is tied to.

HTH,

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org