dcsimg
Setting the "selected" token of an html:options tag dymamically.
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Brendon_Baillod
Posted On:   Thursday, February 12, 2004 05:49 PM

I am having a problem with the struts tags for dynamically setting the "selected" option. I have a collection of reference data (user titles) that I reference to populate a drop down list box using struts: This works quite well to populate the drop down box using an ArrayList of reference data I’ve placed in the session. However, I need to have a specific user title dynamically selected based upon the value of the title field in a user bean, which I’ve also placed in the session. I have access to both the collection of titles and the title of the logged in user, so you would think it wouldn’t be too hard to set which option is selected at runtime. However, I can find no way to   More>>

I am having a problem with the struts tags for dynamically setting the "selected" option.

I have a collection of reference data (user titles) that I reference to populate a drop down list box using struts:

			





This works quite well to populate the drop down box using an ArrayList of reference data I’ve placed in the session. However, I need to have a specific user title dynamically selected based upon the value of the title field in a user bean, which I’ve also placed in the session.

I have access to both the collection of titles and the title of the logged in user, so you would think it wouldn’t be too hard to set which option is selected at runtime. However, I can find no way to do this using the Struts tags and I’d like to avoid coding it manually in a Java scriptlet.

Do you have any suggestions for a better way to dynamically select an option from a drop down list using Struts tags?

Any help would be greatly appreciated.    <<Less

Re: Setting the "selected" token of an html:options tag dymamically.

Posted By:   Pradeep_Singh  
Posted On:   Friday, February 20, 2004 01:43 AM

just write

if you just want to show some selected data then create a method and set the selected value there (whatever u want)just put it on the it will give show u the selected value

Re: Setting the "selected" token of an html:options tag dymamically.

Posted By:   sambasivarao_damerla  
Posted On:   Tuesday, February 17, 2004 03:26 AM

Hi,
How much it is useful to u. In may application i need like this I have a selection box which has to filled with some city name collected from the database. In this cities i have to select one of the city which was already a user selected in the previous page or which was saved in the database. So, the way i followed was as follows.








<%


ArrayList locationsList = (ArrayList)session.getAttribute (WebConstants.LOCATIONBEANLIST);



for(int loclistlen = 0; loclistlen < locationsList.size(); loclistlen++){


locationDetails = (LocationDetailsBean)
locationsList.get(loclistlen);

if(locationDetails.getLocationId() ==
orderDetails.getPreferedLocation()){


%>





<%

}else{

%>





<%

}end of if and else condition.

%>

<%

}//end of for.

%>





in this code the bean orderlist contans ordername, orderdata, locationsid, etc

and in the bean locationsDetails conatins two properties locationsid and locationName



This code was working perfectly to me.



Hope this will useful to u

Re: Setting the "selected" token of an html:options tag dymamically.

Posted By:   Sree_G  
Posted On:   Monday, February 16, 2004 06:23 AM

check ur updateProfileForm property="titles" , ru using same name for both arraylist and property name u may be messing around some where in the form check once again

Re: Setting the "selected" token of an html:options tag dymamically.

Posted By:   oystein_pettersen  
Posted On:   Monday, February 16, 2004 04:52 AM

I am having the same problem. Did you find a good solution to this.

Oystein

Re: Setting the "selected" token of an html:options tag dymamically.

Posted By:   Firat_Tiryaki  
Posted On:   Friday, February 13, 2004 12:59 AM

check out the property fields in the select tag and option tag carefully.
About | Sitemap | Contact