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:
What I have now and is working is:Code:<select> ........ <option value="Greece" selected="selected">Greece</option> ......... </select>
So my question is: how do I select the value I want for the country?Code:<form:form commandName="commandPatient" method="POST" action="editPatient"> ................. <form:select path="country"> <form:options items='${countries}'/> </form:select> ................. </form:form>
I also have declared in my controller a variable with the desired value I want:
I know there is a solution usingCode:protected Map referenceData(HttpServletRequest request) throws Exception { Map<Object, Object> dataMap = new HashMap<Object, Object>(); dataMap.put("country", "Greece"); return dataMap; }
as indicated in: http://www.jroller.com/raible/entry/...ith_spring_mvcCode:<spring:bind path="..."> <select name="${status.expression}"> <c:forEach items="${countries}" var="c"> ........................ </c:forEach> </select> </spring>
but I prefer to use the form:select tag
I just wished there was a "selected" tag
"Thank you for your help"


Reply With Quote
