java - data binding to drop down box in Spring MVC -


i have simple spring mvc web application.i want bind list drop down.in case list items bind drop down; if select item , click submit button passing "0" instead of value.

this controller.

public editemployeecontroller() {         setcommandclass(employee.class);         setcommandname("employee"); }  @override protected map referencedata(httpservletrequest request) throws exception {     map referencedata = new hashmap();             list rolelist = roleservice.listroles();     referencedata.put("rolelist", rolelist);     return referencedata; }  @override protected modelandview onsubmit(httpservletrequest request,         httpservletresponse response,         object command,         bindexception errors) throws exception {     employee employee = (employee) command;     employeeservice.updateemployee(employee);     return new modelandview(getsuccessview()); } 

this view(jsp)

<c:nestedpath path="employee">             <form method="post" action="./editemployee.htm"> ........ .......  select role :                 <c:bind path="roleid">  <select name="rolelists">    <s:foreach items="${rolelist}" var="role" >        <option value="<s:out value="${role.roleid}"/>" <s:if test="${role.roleid == status.value}"> selected="selected"</s:if>><s:out value="${role.title}"/></option>         </s:foreach>   </select> </c:bind> <input type="submit" value="update employee"/ </form> </c:nestedpath> 

any idea solve problem..??

thank in advance!

use spring form tag

add <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> in jsp

and use code below

<form:select path="role"  id="role" >     <form:options items="${rolelist}" itemvalue="roleid" itemlabel="title"/> </form:select> 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -