Announcement Announcement Module
No announcement yet.
sessionForm usage scenarios? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • sessionForm usage scenarios?


    I found sessionForm flag in AbstractFormController. In documentation it is described as follows: "This allows you e.g. to retrieve an object from the database, let the user edit it, and then persist it again". This is common scenario and i had found it useful in my previous projects using struts. Now i'm trying the same thing with sessionForm. I've two controllers - one controller simple (A) retrieves bean from service layer and puts it in session (and shows view) allowing users to submit form into second controller (B). Since i've marked B controller with sessionForm it gets Command object from session instead of calling formBackingObject(). Everything works just fine - but I found it very inconvinient to hardcode very long session attribute name into A controller. Since B controller by default searches sesion using getFormSessionAttributeName() which uses class name plus command name to find a command instance in session. I cannot override getFormSessionAttributeName() in B controller since it's final. I wonder if there is a simple way to guess session attribute name in A controller or force b controller to find Command objects under simpler name. Or maybe this is an antipattern?


  • #2
    Actually it is not an antipattern, rather I didn't understand flow of AbstractFormController and SimpleFormController. Matt's blog ( halped me a lot. The trick is I can use the same controller to show form view (for edit) and for form submission (save changes). It is complete different approach I used to work with struts - but I found it *vert* convinient and clever. In struts I was forced to use different actions (one for show form, one for save changes) or use DispatchAction (but struts actions can have only one associated ActionForm - it is inconvinient when You are forced to use entire form only for indication of entity id You are going to edit).

    I think it would be nice to see much more detailed documentation regerding Controllers in spring documentation.