Back Forum Reply New

posting form to self

Hello.

What I am trying to do is have a page where the user first selects from a select box and then details are displayed depending upon this select, firing a form with an onChange, and a form displayed.

I am trying to do this with the simple form controller but wondering if the multiAction controller or wizardFormController maybe better.

At the moment I am getting this error with my work on the simple form controller

Code:
Neither Errors instance nor plain target object for bean name 'command' available as request attribute
This is my servlet definition

Code:
lt;bean name=quot;userControllerquot;
class=quot;be.eurodyn.costDB.controller.UserGroupControllerquot;gt;
lt;property name=quot;sessionFormquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;
lt;property name=quot;commandClassquot;gt;
lt;valuegt;be.eurodyn.costDB.model.UserGrouplt;/valuegt;
lt;/propertygt;
lt;property name=quot;formViewquot;gt;
lt;valuegt;userslt;/valuegt;
lt;/propertygt;
lt;property name=quot;successViewquot;gt;
lt;valuegt;redirect:users.htmlt;/valuegt;
lt;/propertygt;
lt;!-- lt;property name=quot;validatorquot;gt;
lt;ref bean=quot;userValidatorquot; /gt;
lt;/propertygt;  --gt;
lt;property name=quot;userManagerquot;gt;
lt;ref bean=quot;userManagerquot;/gt;
lt;/propertygt;
lt;property name=quot;applicationSecurityManagerquot;gt;
lt;ref bean=quot;applicationSecurityManagerquot; /gt;
lt;/propertygt;
lt;/beangt;
This is my controller class, onSubmit() it is after this the problem occurs:

Code:
protected ModelAndView onSubmit(fromServletRequest req, fromServletResponse res,Object command, BindException errors){
  Map retMap = new HashMap();   int myGroupId = Integer.parseInt(req.getParameter(quot;groupIDquot;));   logger.info(quot;++++++++ here we are in the onsubmitquot;);   //the user has just selected a group from the top nav to show to the users
   //so go get the relevant users   if(req.getParameter(quot;getUsersquot;) != null){
logger.info(quot;+++++ get users in the onsubmit quot;+req.getParameter(quot;getUsersquot;));
retMap.put(quot;singleGroupquot;, userManager.getSingleGroup(myGroupId));
retMap.put(quot;selectedGroupIDquot;, myGroupId);    }    else{     retMap.put(quot;selectedGroupIDquot;, null);    }

return new ModelAndView(quot;usersquot;, retMap);
}
Now I have tried many ways to return the singleGroup, which is a list of objects, back to the form once the select box is submitted but all throwing up errors this is the closest I have got so far.

This is my JSP outputting the select list:

Code:  lt;spring:bind path=quot;command.groupIDquot;gt;
lt;select name='groupID' onchange=quot;forms.selectGroup.submit();quot;gt;       lt;option value=quot;quot;gt;Select a Group :.lt;/optiongt; lt;c:forEach items=quot;${groupList}quot; var=quot;glquot;gt;
lt;option value=quot;lt;cut value='${gl.groupID}'/gt;quot;
lt;c:if test=quot;${gl.groupID == selGroupID}quot;gt;SELECTEDlt;/c:ifgt;gt;
lt;cut value=quot;${gl.groupACYN}quot;/gt; lt;cut value=quot;${gl.groupDESC}quot;/gt;
lt;/optiongt;       lt;/c:forEachgt;       lt;/selectgt;   lt;/spring:bindgt;
singleGroup that I am returning to the form is going to be an output of details of the group that has been selected by the user originallly.

Any pointers in the right direction would be superb.

Thanks for reading
cheers
Martin

Just picked up your error message without reading the rest of your message, so I have no idea about what you are trying to do

You need to add errors.getModel() to the ModelAndView you return from onSubmit.

Ok I managed to get this going in the end although I don't know if this is the best approach.

I have a group select box that is set up by reference data:

Code: Map retMap = new HashMap(); //list of groups to output to the select list retMap.put(quot;groupListquot;,userManager.getAllGroups()); return retMap;
This user selects from this group select box which fires the form in an onChange handler, this select box is NOT bound to anything.  
The class is then called with onSubmit method which has logic to determine if the group select box has been selected from it then goes and gets relevant details

Code:
protected ModelAndView onSubmit(fromServletRequest req, fromServletResponse res,Object command, BindException errors){ Map retMap = new HashMap(); int myGroupId = Integer.parseInt(req.getParameter(quot;groupIDquot;));
//the user has just selected a group from the top nav to show to the users //so go get the relevant users if(req.getParameter(quot;getUsersquot;) != null){       //put the id from the group select box back to the form
retMap.put(quot;selectedGroupIDquot;, myGroupId);      //go get the group of users that is requested from the select box
retMap.put(quot;singleGroupquot;,userManager.getSingleGroup(myGroupId)); }
//here we can have more if/else if we are doing a third post of the form etc else{        retMap.put(quot;selectedGroupIDquot;, null);
}
Now the problem is when we go get the single group our original group select box has no data so we need to go and get the reference data again and send it back to the form

Code: try {retMap.putAll(referenceData(req));}  catch (Exception e) {e.printStackTrace();}
Now we send back the model with all the stuff that we have setup for the form

Code: ModelAndView mav = new ModelAndView(quot;usersquot;,retMap); mav.addObject(quot;errorsquot;, errors.getModel()); return mav;
My question is I am sure there is a better way to do this like using formBackingObject or something.  here there is a lot going on in the onSubmit function.

Any advice or theories on a better cleaner way to do this or is this technique the norm, it works!

thanks for reading and happy springing.
cheers
Martin

Ok I am getting this error again, the main reason is I have put the form binding back into the mix.  I would like to be able to do this posting a form to itself with the binding....

so can someone explain what exactly is going on, what does this error mean and what produces it

Code:
Neither Errors instance nor plain target object for bean name 'frameProfile' available as request attribute
With that info I maybe able to sort this out.

thanks for reading:
cheers
Martin

I dont have a complete answer for you, but was running into the same type of problem when I created a form that paged through a list and wanted the next button on the form to post to the same page with the next batch of data.  What was happening to me when I was getting that error was that I did not fully understand the life cycle of the controller I was using.  When using the simpleFormController, a GET transaction will run my formBackingObject and referenceData methods so that I can set up the form initially, but after a POST, those methods do not run and the beans that the JSP expect so see are not there so I get the error.  Spring makes the assumption (at least with the SimpleFormController) that a GET means form entry and a POST means form submission.  I was trying to pervert that model and got into trouble.  I fixed my problem by extending abstract controller and just did a request.getParameter to pick off the one form value that I wanted (next or prior on list navigation).  A cheap answer, but it got me out of a similar bind (ok, bad pun).  

You might be able to manually populate the model with the necessary beans in the onSubmit method so that they are there when you re-view the form, or perhaps pervert the validation to actually run your form logic, throwing an quot;errorquot; with each submission so that the reference data is there on each pass back through the form, and just don't put an error in the errors object when you want to exit to the successView, but you also might find yourself jurry rigging the logic in a manner that will make future support difficult.
¥
Back Forum Reply New