spring mvc - getting null value in the controller while submitting the form -


here submitting form using submit action. in controller model object showing null value. suppose using request.getparameter("mcodename") - getting value. whey value null when using getmcode() method. please me resolve issue.

 @requestmapping(value="/mastercode.do", method=requestmethod.post)     public modelandview addmastercode(httpservletrequest req,              httpservletresponse res, @modelattribute("mastercodebean") mastercodebean mcodebeanobj) {          log.info("");         string mcodename    = mcodebeanobj.getmaster_code_name(); //getting null         string mcodestatus  = mcodebeanobj.isactive(); //getting null         system.out.println("req code des " + req.getparameter("mcodename"));         system.out.println("req active : " + req.getparameter("active"));         modelandview model = null;         try {             model = new modelandview("mastercode");             codedelegate.addmastercodedetails(mcodebeanobj);             model.addobject("mastercodebean", mcodebeanobj);         }catch(exception e) {             system.out.println(excep_err);         }         return model;     } 

my form bind model attribute

sorry dont have enough reputations comment on. writing answer here.

`<form:form id="mcodeform" method="post" action="mastercode.do" modelattribute="mastercodebean">  enter product name : <form:input id="mcodename" path="mcodename" /> <br> select status : <form:select id="active" path="isactive">  <form:option value="0" label="active" />  <form:option value="1" label="de-active" />  </form:select>  <span> <input type="submit" value="save" id="save_mstcdemgr"/> </span> </form:form>` 
  1. the setters , getters should follow code conventions. suppose if have mcodename class variable getmcodename() , setmcodename(string mcodename).

  2. as used form tag, path nothing modelattribute field name. no need of writing id , name attributes generates them @ run-time. id needed client-side validation or javascript related purposes.

    <form:input id="mcodename" path="mcodename" /> converted html code @ run-time <input type="text" id="mcodename" name="mcodename" />

try , let me know.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -