Results 1 to 3 of 3

Thread: form:select tag [chose one option as selected]

Threaded View

  1. #1
    Join Date
    Nov 2009
    Posts
    5

    Default form:select tag [chose one option as selected]

    Hi! I am doing a project for my university and I have been a while gloogling for a solution about how to select one of the options in a dropdown list, but I was not fortunate.
    - I am using Hibernate and Spring MVC.
    - I have an entity "patient" which has a field "country" of type String.

    In one of the pages I have to edit the values of the patient and I need that the dropdown list is initialized with the correct value. I know how to retrieve the data and all that,
    Which I do not know is how to translate:

    Code:
    <select>
       ........
      <option value="Greece" selected="selected">Greece</option>
      .........
    </select>
    What I have now and is working is:

    Code:
    <form:form commandName="commandPatient" method="POST" action="editPatient">
    .................
    <form:select path="country">
       <form:options items='${countries}'/>    
    </form:select>
    .................
    </form:form>
    So my question is: how do I select the value I want for the country?
    I also have declared in my controller a variable with the desired value I want:

    Code:
        protected Map referenceData(HttpServletRequest request) throws Exception {
        	Map<Object, Object> dataMap = new HashMap<Object, Object>();
        	dataMap.put("country", "Greece");
            return dataMap;
        }
    I know there is a solution using
    Code:
    <spring:bind path="...">
           <select name="${status.expression}">
               <c:forEach items="${countries}" var="c">
    ........................
             </c:forEach>
           </select>
    </spring>
    as indicated in: http://www.jroller.com/raible/entry/...ith_spring_mvc
    but I prefer to use the form:select tag
    I just wished there was a "selected" tag
    "Thank you for your help"
    Last edited by raulsan; Nov 23rd, 2009 at 06:00 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •