forms - Doing a post request to a spring 2.0 controller -
i have form on html page this:
<form id="profileform" method="post" action="myapp/profile/save.do"> <input type="text" name="profilelist[0].name" value="jane"/> <input type="text" name="profilelist[1].name" value="john"/> <input type="text" name="profilelist[2].name" value="alice"/> </form>
when submit form, post request send spring dispatcher servlet, calls controller:
public class save extends simpleformcontroller { @override protected object formbackingobject(httpservletrequest request) throws exception { //this method runs fine. profilefbo profilefbo = new profilefbo(); return profilefbo; } @override protected modelandview onsubmit(httpservletrequest request, httpservletresponse response, object command, bindexception errors) throws exception { //this method doesn't run map<string, object> modeldata = new hashmap<string, object>(); return showform(request, response, errors, modeldata); } }
the first method runs, second doesn't. must go wrong binding submitted data fbo? here's fbo, nothing container list of profiledto objects:
public class profilefbo { private list<profiledto> profilelist; public list<profiledto> getprofilelist() { return profilelist; } public void setprofilelist(list<profiledto> profilelist) { this.profilelist = profilelist; } }
and of course, profiledto object has property called "name" , appriopate getter/setter.
here's spring.xml configuration:
<bean id="profilesavecontroller" class="com.company.profile.controller.save"> <property name="successview" value="profileoverviewpagetile"/> <property name="commandname" value="profilefbo"/> <property name="commandclass" value="com.company.profile.fbo.profilefbo"/> </bean>
as can see, i'm not using controller request, i'm not ùmaking full use of spring form controller functionality. purely doing post requests , binding form fbo object.
what doing wrong in setup?
wow, that's old school!
i don't see myapp/profile/save.do endpoint calling in html defined.
you should using spring jsp tags this:
<form:form method="post"commandname="profilefbo">
that should hit correct backend endpoint.
you know shouldn't handling forms anymore, right?
Comments
Post a Comment