Hi!
I've got a question on spring form.
I need to save a command object in the session. I used Code:
setSessionForm(true)
And I suppose that backing object will be saved in a session, but it doesn't happen Could you explain why?
Have you checked if every request goes thrue the method formBackingObject()?
Originally Posted by alfaI used Code:
setSessionForm(true)At which point are you doing that?
to manifoldronin:
At the constructorCode:
public FormController() { this.setCommandName(COMMAND_NAME); this.setCommandClass(FormBackingObject.class); this.setSessionForm(true); }
Originally Posted by brlimaHave you checked if every request goes thrue the method formBackingObject()?
What do you mean? As I know it happens everytime when user submit a form, if no errors. In my case no errors and formBackingObject() method calling everytime.
Originally Posted by alfaHi!
I've got a question on spring form.
I need to save a command object in the session. I used Code:
setSessionForm(true)
And I suppose that backing object will be saved in a session, but it doesn't happen Could you explain why?
Sure. SessionForm does not save the backing object in the session permanently. It only saves it in the session between the initial view of the form and its submission before removing the object. (With sessionForm=false, two instances of the command bean are created, one for initial view and one to handle form submission.)
Perhaps if this property were called RequestForm it would be less confusing.
What you probably want to do instead, within your onSubmit() or onBindAndValidate() of your SFC: Code:
fromSession session = request.getSession(true);
session.setAttribute(quot;someObjectNamequot;, myObject);
Glen
Originally Posted by gmazzaSure. SessionForm does not save the backing object in the session permanently. It only saves it in the session between the initial view of the form and its submission before removing the object. (With sessionForm=false, two instances of the command bean are created, one for initial view and one to handle form submission.)
Perhaps if this property were called RequestForm it would be less confusing.
What you probably want to do instead, within your onSubmit() or onBindAndValidate() of your SFC: Code:
fromSession session = request.getSession(true);
session.setAttribute(quot;someObjectNamequot;, myObject);
Glen
do you know where and how the command object is stored after calling the formBakingObect() method? I have seen in AFC that in getComand() method it is removed, but somehow onSubmit still return it to me
Originally Posted by orussoI have seen in AFC that in getComand() method it is removed, but somehow onSubmit still return it to me
I don't believe so--if sessionForm=false, onSubmit() is giving you a new instance of the commandBean, with values populated from the form submission.
But to find out the answer to your question, I would search the Spring source for sessionForm or getSessionForm() -- it is this parameter that drives much of the business logic in terms of removing/adding command beans to the session.
Glen |