java - Spring form ID field not populated on POST -
in below spring form, object's id field populated, when receive submission in controller method, of form's fields populated except id field. i've quintuple-checked field type , getter/setter types same non-primitive, i've seen many of other questions on similar , seems mutual issue. controller doesn't have method-level @modelattributes, isn't beingness populated otherwise.
here's declaration of post method, debugged on first containing line , found form's id field empty:
@requestmapping(value="/{orgid}", method=requestmethod.post) public string editorganizationpost(@pathvariable int orgid, @valid @modelattribute(org_form) organizationform orgform, bindingresult result, redirectattributes att, httpservletrequest request) {
here's form object:
public class organizationform { private integer id; @notblank private string name; @notblank private string description; private set<user> users; int movetoorganizationid = 0; string movetoorganizationname; int[] movefromorganizationuserselect = null; // list of selected users // moved new // organization public integer getid() { homecoming id; } public void setid(integer id) { this.id = id; } public string getname() { homecoming name; } public void setname(string name) { this.name = name; } public string getdescription() { homecoming description; } public void setdescription(string description) { this.description = description; } public set<user> getusers() { homecoming users; } public void setusers(set<user> users) { this.users = users; } public int getmovetoorganizationid() { homecoming this.movetoorganizationid; } public void setmovetoorganizationid(int movetoorganizationid) { this.movetoorganizationid = movetoorganizationid; } public string getmovetoorganizationname() { homecoming this.movetoorganizationname; } public void setmovetoorganizationname(string movetoorganizationname) { this.movetoorganizationname = movetoorganizationname; } public int[] getmovefromorganizationuserselect() { homecoming this.movefromorganizationuserselect; } public void setmovefromorganizationuserselect( int[] movefromorganizationuserselect) { this.movefromorganizationuserselect = movefromorganizationuserselect; } public boolean isnew() { homecoming this.id == null || this.id == 0; } }
here markup jsp file:
<form:form method="post" action="${submiturl}" commandname="organizationform"> <form:errors path="*" /> <form:hidden path="id" /> <table class="admintable editcontent"> <tr class="bg_lgtgrey"> <td><fmt:message key="manageorganizations.organizationform.name" />:</td> <td><form:input path="name" cssclass="inputbox" tabindex="4" /></td> </tr> <tr class="bg_lgtgrey"> <td><fmt:message key="manageorganizations.organizationform.description" />:</td> <td><form:textarea path="description" cssclass="inputbox" tabindex="4" /></td> </tr> <tr> <td colspan="2" align="right"><c:choose> <c:when test="${!organizationform.new}"> <input type="submit" class="btn btn-primary" id="submit_button" value="update" /> </c:when> <c:otherwise> <input type="submit" class="btn btn-primary" id="submit_button" value="create" /> </c:otherwise> </c:choose></td> </tr> </table> </form:form>
and here generated html:
<form id="organizationform" action="/admin/organizations/1" method="post"> <input id="id" name="id" type="hidden" value="1"> <table class="admintable editcontent"> <tbody><tr class="bg_lgtgrey"> <td>organization name:</td> <td><input id="name" name="name" class="inputbox" tabindex="4" type="text" value="organization1"></td> </tr> <tr class="bg_lgtgrey"> <td>organization description:</td> <td><textarea id="description" name="description" class="inputbox" tabindex="4"></textarea></td> </tr> <tr> <td colspan="2" align="right"> <input type="submit" class="btn btn-primary" id="submit_button" value="update"> </td> </tr> </tbody></table> </form>
i used chrome devtools grab post info , here is:
id=1&name=organization1&description=
...yet @ breakpoint @ first line of editorganizationpost method, form.id field set 0.
i have spent forever trying figure out why bind name , description not id when sent. inject id path variable dumbfounded why wouldn't populate field naturally.
i had same problem.. id field set 0. changing id field else didn't work either. after more nail , trail, removing
disabled="true"
from
<form:input path"id" disabled="true"/>
fixed issue. assumed <form:hidden path="id">
give same error didn't.
java forms spring spring-mvc
No comments:
Post a Comment