java - Binding modelAttribute from jsp to controller -


this controller class:

@controller @sessionattributes({"list", "selectedcompany"}) public class prospectcontroller {  protected static logger logger = logger.getlogger("controller");  @resource(name = "prospectwebservicetemplate") private webservicetemplate prospectwebservicetemplate; @resource(name = countrywebservicetemplate") private webservicetemplate countrywebservicetemplate; @resource(name = "companywebservicetemplate") private webservicetemplate companywebservicetemplate;  /**  * handles , retrieves subscribe page  */ @requestmapping(value = "/addprospect", method = requestmethod.get) public string getaddprospectpage(@modelattribute("prospectattribute") prospectdto prospectdto,model model) {     logger.debug("received request show add prospect page");      final getallcountriesrequest request = new getallcountriesrequest();     getallcountriesresponse response = (getallcountriesresponse) countrywebservicetemplate             .marshalsendandreceive(request);       list<countrydto> list = new arraylist<countrydto>();     list<countrydto> allcountries =  response.getcountriesdto();     if (response != null && allcountries != null) {         (countrydto dto : allcountries) {             list.add(dto);         }     }      model.addattribute("list", list);      final getallcompaniesrequest requestcomp = new getallcompaniesrequest();     getallcompaniesresponse responsecomp = (getallcompaniesresponse) companywebservicetemplate             .marshalsendandreceive(requestcomp);      list<companydto> listcomp = new arraylist<companydto>();     list<companydto> allcompanies =  responsecomp.getcompaniesdto();     if (responsecomp != null &&  allcompanies != null) {         (companydto dto : allcompanies) {             listcomp.add(dto);         }     }     model.addattribute("listcomp", listcomp);        model.addattribute("prospectattribute", new saveprospectrequest());     return "addprospect"; }   @requestmapping(value = "/saveprospect", method = requestmethod.post) public string dosave(         @modelattribute("prospectattribute")  saveprospectrequest request,         model model) {     logger.debug("received request subscribe");     try {         saveprospectresponse response = (saveprospectresponse) prospectwebservicetemplate                 .marshalsendandreceive(request);         logger.debug(response.getid());          model.addattribute("response", "success! ");         model.addattribute("prospect", response.getfirstname());      } catch (soapfaultclientexception sfce) {         logger.error("we sent invalid message", sfce);         model.addattribute("error",                 "validation error! cannot process subscription");      } catch (exception e) {         logger.error("unexpected exception", e);         model.addattribute("error",                 "server error! unexpected error has occured");     }      model.addattribute("prospectattribute", request);      return "addprospect"; } 

}

this jsp file

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>     <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>     <%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%>     <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">    <html>  <head>   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">   <title>prospect</title>   </head>   <body>  <c:url var="addurl" value="/example/saveprospect" /> <form:form modelattribute="prospectattribute" method="post"     action="${addurl}">     <table>         <tr>             <td><form:label path="prospectdto.firstname">first name:</form:label></td>             <td><form:input path="prospectdto.firstname" /></td>         </tr>         <tr>             <td><form:label path="prospectdto.lastname">last name:</form:label></td>             <td><form:input path="prospectdto.lastname" /></td>         </tr>         <tr>             <td><form:label path="prospectdto.function">function:</form:label></td>             <td><form:input path="prospectdto.function" /></td>         </tr>         <tr>             <td><form:label path="prospectdto.email">email:</form:label></td>             <td><form:input path="prospectdto.email" /></td>         </tr>         <tr>             <td><form:label path="prospectdto.telephone">telephone:</form:label></td>             <td><form:input path="prospectdto.telephone" /></td>         </tr>         <tr>             <td><form:label path="prospectdto.typelead">type lead:</form:label></td>             <td><form:select path="prospectdto.typelead">                     <form:option value="">-- select type lead --</form:option>                     <form:option value="lead1">lead1</form:option>                     <form:option value="lead2">lead2</form:option>                     <form:option value="lead3">lead3</form:option>                     <form:option value="client">client</form:option>                     <form:option value="refuse">refuse</form:option>                 </form:select></td>         </tr>         <tr>             <td><form:label path="prospectdto.company">company:</form:label></td>              <td><form:select path="prospectdto.company">                          <form:option value="">-- select company --</form:option>                          <c:foreach items="${listcomp}" var="company"> --%>                             <form:option value="${company.id}">${company.name}</form:option>                          </c:foreach>              </form:select></td>           </tr>         <tr>             <td colspan="4"><input type="submit" value="addprospect"                 /></td>         </tr>     </table> </form:form>  </body>  </html> 

i have company list in controller class , when send jsp file works. but, in browser, when select company combobox, should send "dosave" method of controller class modelattribute of type prospect contains company doesn't work! problem?


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -