views:

1411

answers:

1

I am using SimpleFormController in my application to handle form submisions. one thing i am missing is the request object that is passed onSubmit(request,response..) is a different one from the initial request object that is received by formBackingObject(..).probably because it is again a new request from web.

i just want to use the same parameters from request object in onSubmit(..) that i was able to access in formBackingObject(..).

it could be possible for me to store them in and pass thru hidden fields from jsp, but i am trying to get some elegant approach.

is there any way to achieve this?

EDIT:

i am overriding

formBackingObject(HttpServletRequest request)`  

and

onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)

methods in my class.

for the intial view formbackingObject(..) will be called and i will have some variables from the request object then if user submits the form onSubmit(..) will be called then i will have another request object which is different from the one i received in formbackingObject(..) .

what i am asking is, is there any way of holding the initial 'request' parameters(request.getParameter() kind of...) so that i can use them in onSubmit(..) with out sending them back & forth thru hidden fields ?'

+1  A: 

The formBackingObject() method is being called when the user makes the request for the initial form view. This is a completely separate HTTP request to when the user submits the form which is when the onSubmit() method is called.

If you want to save state from the first HTTP request so it is available in the second HTTP request, your best option is probably to save it in the HTTP session.

eg: in your formBackingObject() method:

HttpSession session = request.getSession();
session.setAttribute("param1", request.getParameter("param1"));
session.setAttribute("param2", request.getParameter("param2"));

and in your onSubmit() method:

HttpSession session = request.getSession();
String param1 = (String) session.getAttribute("param1");
String param2 = (String) session.getAttribute("param2");
Shane Bell
Thanks Shane ! probably that's the only way as it is a completely new HTTP request.
sangram