Announcement Announcement Module
No announcement yet.
Adding a 'Please Select...' label to form:select form:options Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding a 'Please Select...' label to form:select form:options

    Not sure if others are having this problem, but I had to do a bit of research for a very simple and likely very common issue.

    Roo generated forms that create select lists default to the first value that the select is bound to. Not exactly a good default starting point in my mind.

    Here is an example of how you can improve an 'optional' select list to show a title value rather than defaulting to the first item in the list:

                <div id="roo_staffprofile_person">
                    <c:if test="${not empty people}">
                        <label for="_person_id">Person:</label>
                        <form:select cssStyle="width:250px" id="_person_id" path="person">
                            <form:option value="0" label="--- Select ---" />
                            <form:options itemValue="id" items="${people}" itemLabel="KnownAs"/>
                        <script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : '_person_id', widgetType: 'dijit.form.FilteringSelect', widgetAttrs : {hasDownArrow : true}})); </script>

  • #2
    Here is the link to Spring documentation:


    • #3
      Forms4j ( has a hint attribute that does exactly this -- along with automatic server side validation that ensures the "Please select..." option is not submitted.

      <forms4j:select id="foo" hint="Please select...">
      	<forms4j:option value="apple" label="Apples" />
      	<forms4j:option value="orange" label="Oranges" />