Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

set html:option to defalut bean value

 
alan wamser
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
jandhyala sastry
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic