• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

set html:option to defalut bean value

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main advantage the <html:select><html:option> 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 ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the solution it is working fine.

Merrill Higginson wrote:The main advantage the <html:select><html:option> 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 ]

 
reply
    Bookmark Topic Watch Topic
  • New Topic