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>` the setters , getters should follow code conventions. suppose if have
mcodenameclass variablegetmcodename(),setmcodename(string mcodename).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
Post a Comment