jsp - Form inheritance in Spring MVC -
i facing situation in spring mvc application have form common pages. so, took form in separate jsp page , included page in other jsp pages. form simple:
<form:form method="post" commandname="coachingdomain" action="searchform"> <form:input path="coachingname" placeholder="search coaching" /> <button type="submit" value="search">search</button> </form:form>
now scene when run application, server not able find binding of coachingdomain in controller. make more clear, suppose form present in page a1 , included in page a2. in a2 controller, have bind coachingdomain given below:
@requestmapping(method = requestmethod.get) public string showpage(modelmap modelmap, httpservletrequest request, httpservletresponse response) { modelmap.addattribute("coachingdomain", new coachingdomain()); return "welcome"; }
but bind error still appeared. seems me server trying find controller of a1 page first. so, created a1 controller (as abstract) , made a2 extend a1 controller. then, placed same code in a1. still same error there.
my a1 , a2 controllers are:
public abstract class a1 { public void showpage1(modelmap modelmap, httpservletrequest request, httpservletresponse response) { system.out.println("a1 called"); modelmap.addattribute("coachingdomain", new coachingdomain()); } } @controller @requestmapping(value = "/a2.html") public class a2 extends a1 { @requestmapping(method = requestmethod.get) public string showpage(modelmap modelmap, httpservletrequest request, httpservletresponse response) { system.out.println("a2 called"); showpage1(modelmap, request, response); modelmap.addattribute("searchcoachingdomain", new searchcoachingdomain()); return "a2"; } }
my jsp pages are:
a1.jsp:
<body> <form:form method="post" commandname="coachingdomain" action="searchform"> <form:input path="coachingname" placeholder="search coaching" /> <button type="submit" value="search">search</button> </form:form> </body>
a2.jsp:
<%@include file="/web-inf/views/root.jsp"%>
and error is:
neither bindingresult nor plain target object bean name 'coachingdomain' available request attribute @ org.springframework.web.servlet.support.bindstatus.<init>(bindstatus.java:141) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getbindstatus(abstractdataboundformelementtag.java:174)
there inheritance examples given in internet not able make how to make form common jsp pages. 1 approach think of may using javascript bind submit button js function , make call required url. hoping if same can achieved using spring mvc @requestmapping(method = requestmethod.post) technique. please suggest me out here...
Comments
Post a Comment