View Full Version : Unsuccessful spring:bind
DJViking
Jul 13th, 2007, 04:29 AM
I an trying to use <spring:nestedPath> and <spring:bind> in my JSP code but it fails.
<spring:nestedPath path="someService">
<form>
....
<spring:bind path="serviceVariable>
<input type text="${status.expression} value="${status.value}">
</spring:bind>
...
</spring:nestedPath>
The error message goes like this:
Neither BindingResult nor plain object for bean name "someService" avaiable as request attribute
I followed some code examples of a book.
Also I have set in the Controller constructor
setCommandName("someService");
setCommandClass(someServiceForm.class);
I have a ModelAndView onSubmit method which returns a map of some objects.
DJViking
Jul 13th, 2007, 08:50 AM
I think I found out why I can't access the command object via <spring:bind>
My Service selector form is responsible for dispatching the selected form view.
1. When I start the application the DispatcherServlet dispatches to ServiceController and initally this one shows the formView of the Service selector form(Where the user selects which form according to a service)
2. When a service is choosen the ServiceController is again called. The view for that form is choosen as the successView and viewed.
Each form has its own controller.
Therefore when I access the command object it is the ServiceController's Command object and not the command object belonging to the forms Controller. The forms controller is called when that form is submitted.
Anyone know a way I could fix this so that when a service form is viewed that command object is used?
Marten Deinum
Jul 13th, 2007, 08:59 AM
It looks like you are trying do something wizard like. I suggest I take a look at the AbstractWizardFormController (http://www.springframework.org/docs/api/org/springframework/web/servlet/mvc/AbstractWizardFormController.html)
DJViking
Jul 13th, 2007, 09:20 AM
It looks like you are trying do something wizard like. I suggest I take a look at the AbstractWizardFormController (http://www.springframework.org/docs/api/org/springframework/web/servlet/mvc/AbstractWizardFormController.html)
I just don't see it. What I read about AbstractWizardFormController it is if you have a form that goes over meny form pages(i.e. back, next, etc.)
Ì do not want the back and next function.
All I want to do is first display a service selector and after the user selects a form that form is displayed. But I want that forms controller to take charge after the ServiceController has processed the submit and figured out which form to show.
Is it not possible to redirect controll from one controller to another? When ServiceController has determined which view it dispatches to that views controller
Marten Deinum
Jul 13th, 2007, 09:48 AM
The ServiceController doesn't need to figure out which form to show. The form controller must do that or at least both have to do that.
If you want to redirect simply do it. redirect to the url which matches your controller, don't redirect to the view but to the url controller. ie.e form1.do, form2.do etc. instead of form1_view or form2_view.
Everything you put in the model will be appended to the URI as request parameters. All this is explained in the reference guide (http://static.springframework.org/docs/reference/mvc.html) which I'm going to suggest again :).
DJViking
Jul 13th, 2007, 09:54 AM
The ServiceController doesn't need to figure out which form to show. The form controller must do that or at least both have to do that.
If you want to redirect simply do it. redirect to the url which matches your controller, don't redirect to the view but to the url controller. ie.e form1.do, form2.do etc. instead of form1_view or form2_view.
Everything you put in the model will be appended to the URI as request parameters. All this is explained in the reference guide (http://static.springframework.org/docs/reference/mvc.html) which I'm going to suggest again :).
The ServiceController knows which form to show because the service form jsp file calls the ServiceController after the user has selected a service
I have read chapter 13 of the reference guide. RedirectView is the way to go as I understand, but I can't get it to work.
My form controller has the URL of /Service1
By doing
new ModelAndView(new RedirectView("/Service1"));
Nothing happens. I just get an HTTP 404
I am using SimpleUrlHandlerMapping with InternalResourceViewResolver
Edit: Dropping the / before Service1 worked
RedirectView view = new RedirectView();
view.setUrl("Service1");
return new ModenAndView(view);
The problem with the reference manual it does not contain examples. Did alot of trial and error to figure it out.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.