Is there any way to select current value in dropdown list by Spring MVC by <form:options>
?
No need to use if else
Example:
Student student = new Student();
student.gender = "F";
model.addObject("student", student);
Map<String, String> genders = new LinkedHashMap<String, String>();
genders.put("M", "Male");
genders.put("F", "Female");
model.addObject("genders", genders);
JSP Code
modelAttribute
& commandName
are interchangeable
<c:url value="/Student/Edit" var="editstudenturl"/>
<form:form method="post" action="${editstudenturl}" modelAttribute="student" class="form-horizontal">
<form:select path="gender" class="form-control" id="gender" >
<form:options items="${genders}" />
</form:select>
</form:form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With