aspose file tools*
The moose likes Struts and the fly likes set html:option to defalut bean value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "set html:option to defalut bean value" Watch "set html:option to defalut bean value" New topic
Author

set html:option to defalut bean value

alan wamser
Ranch Hand

Joined: Jan 30, 2006
Posts: 41
I need to set the defalut value of a html:select/html ption to a value in the current form bean. The form is used to update a users current manager. I'm using AJAX to update the <html:select> if the manager needs to change, but I still need to display the current manager in the drop down.

I tried to do a value<bean:write name="transferForm" property="currentManager" />" but the <html ption> doesn't like that...

<html:select property="currentManager" >
<html ption value="???"></html ption>
</html:select>
alan wamser
Ranch Hand

Joined: Jan 30, 2006
Posts: 41
this works, I'm not sure if its good design to mix html with struts tags.

<option value="<bean:write name="transferForm" property="currentManager" />"><bean:write name="transferForm" property="currentManager" /> </option>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The main advantage the <html:select><htmlption> combination offers over using the plain html versions of the tags is that the option that matches the value of the form bean's property specified in the <html:select> tag will automatically show as selected when the page is displayed. If you don't need this functionality (and you don't if there's only one option), you might as well just use the plain html tags.

The code below will work just fine.

<select name="currentManager">
<option value="<bean:write name="transferForm" property="currentManager" />"><bean:write name="transferForm" property="currentManager" /> </option>
</select>

The question arises, though: Why are you only showing the current manager in the list, and not the entire list of managers to choose from? As explained above, if you use the <html:select> tag properly, you can show the entire list and have the current manager pre-selected on that list.
[ March 15, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
jandhyala sastry
Greenhorn

Joined: Apr 28, 2004
Posts: 9
Thanks for the solution it is working fine.

Merrill Higginson wrote:The main advantage the <html:select><htmlption> combination offers over using the plain html versions of the tags is that the option that matches the value of the form bean's property specified in the <html:select> tag will automatically show as selected when the page is displayed. If you don't need this functionality (and you don't if there's only one option), you might as well just use the plain html tags.

The code below will work just fine.

<select name="currentManager">
<option value="<bean:write name="transferForm" property="currentManager" />"><bean:write name="transferForm" property="currentManager" /> </option>
</select>

The question arises, though: Why are you only showing the current manager in the list, and not the entire list of managers to choose from? As explained above, if you use the <html:select> tag properly, you can show the entire list and have the current manager pre-selected on that list.
[ March 15, 2006: Message edited by: Merrill Higginson ]


SCJP, SCWCD, SCBCD<br /> <br />Thanks in advance!<br />Jandhyala Sastry.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: set html:option to defalut bean value