Hi folks,
i'm new in spring and have a problems putting two forms on one page, i want each form will be bind to some SimpleFormController
any help will be appreciate
thanks in advance
Hi folks,
i'm new in spring and have a problems putting two forms on one page, i want each form will be bind to some SimpleFormController
any help will be appreciate
thanks in advance
There are a number of posts about this, try searching.
For my two cents, I would probably approach this by having each form post to a seperate controller. Have both controllers have the same success page.
hey guys, first of all thanks for reply.Originally Posted by socotech
i'm trying to have two separate forms with two distinct controllers on one JSP page but already on GET i receive following error:
javax.servlet.ServletException: Neither Errors instance nor plain target
object for bean name 'userInfo' available as request attribute
I found that i can solve it by having two pages for each controller and when using include tag in my main page, i didn't try it yet and still optimistic to find more elegant way.
I dont think this issue is related to having two forms in one JSP. This just means you're calling
with no object named userInfo in your page context. Implement the method formBackingObject in your controller to return the object that you want to acess via the spring:bind tag, and call setCommandName("userInfo") in your controller's contstructor.Code:<spring:bind path="userInfo">...</spring:bind>
alternatively, if you are building the page using a model, ensure the userInfo object is in your model.
cheers, toby
But my page has two forms and hence formBackingObject has to return two objects, i guess that when i redirect to my aforementioned page using SimpleUrlHandlerMapping i actually activate only one controller which is return only one object to access.
is this the cause of the problem?
Thank you.
You have two options:
I would use an AbstractCommandController implementation to build the formView page model, placing the two objects you need as command objects into the model.
The alternative is to use the referenceData method of one of your form controllers, but this would make one controller depend on the other being present in the same page.Code:public ModelAndView handle(...) { return new ModelAndView("formViewPage.jsp") .addObject("cmdObjectOne" userInfo) .addObject("cmdObjectTwo" companyInfo); }
cheers, toby
thanks,
it may be a stupid question but which object should be the CommandClass?
whatever the class of your userInfo object is. if you do this:
Then do this in you constructor:Code:MyUserInfo userInfo = new MyUserInfo();
The command class is just whatever you want spring to bind the form fields to automatically. It can be any java bean you like.Code:setCommandClass(MyUserInfo.class);
Thank you.