Results 1 to 8 of 8

Thread: AbstractWizardFormController or Spring WebFlow?

  1. #1
    Join Date
    Jan 2006
    Posts
    15

    Default AbstractWizardFormController or Spring WebFlow?

    I need to create a form that has multiple checkboxes (all for the same form field) that span multiple pages (much like selecting emails in Gmail or Hotmail when they all aren't listed on a single page).

    The form is for creating an Account. Part of this process involves selecting a subset of Stores that are to belong to the account. Stores are stored in a Set in the Account.

    Is this even possible? I've seen posts on checkboxes and Sets using name=paramName and a hidden name=_paramName, but they seem to only address having all checkbox options on a single page.

  2. #2
    Join Date
    Jan 2006
    Posts
    15

    Default

    i think my title is misleading...

    the core issue is figuring out how to handle multiple checkboxes that spans multiple pages.

    this is where my research has me thus far:

    (1) override createBinder in my form controller
    (2) sub-class ServletRequestDataBinder and override the doBind inherited from WebDataBinder.

    whereas the original doBind (before overriding) would make my Set have a value of null, my new doBind (after overriding) will remove all the Stores presented on the current page from the Set.

    how right or wrong am i?
    Last edited by daniel.smith; Feb 22nd, 2006 at 09:33 AM.

  3. #3
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    I would probably take a different approach

    The reason the usual approach won't work is because (as you identified) you are submitting the entire set of checkboxes over more than one request, however, the entire set of checkboxes on the formBackingObject is overridden per request.

    To resolve this you need to "remember" the previously selected checkboxes over each request. Two possible solutions:

    - include the previously selected checkboxes as hidden fields in the next page (urgh, horrible, just so wrong)
    - don't allow your formBackingObject.setSelectedCheckBoxes(Object[] selected) to overwrite your set, so rather than:

    Code:
      class MyFormBackingObject {
        private Set theSelectedObjects;
    
        public void setSelectedObjects(final Object[] selectedObjects) {
          this.theSelectedObjects = new HashSet(Arrays.asList(selectedObject));
        }
      }
    simply do this:

    Code:
      class MyFormBackingObject {
        private Set theSelectedObjects;
    
        public void setSelectedObjects(final Object[] selectedObjects) {
          this.theSelectedObjects.addAll(new HashSet(Arrays.asList(selectedObject)));
        }
      }
    in otherwords, keep adding to the set instead of replacing the set (or list whatever).

    To do this you obviously need to store your formBackingObject in session (or flow if you are using spring web flow).

    HTH.

  4. #4
    Join Date
    Jan 2006
    Posts
    15

    Default

    this is definitely a push in the right direction.

    based on my understanding, additional logic would have to be built in to handle the ability to uncheck a Store, correct?

  5. #5
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Good point. If you submit the checkboxes, the FBR is updated, if there are then validation errors and you choose fewer options, then the selected checkboxes will always be in the FBR.

    I presume you have a notion of the items displayed on each page, so before onBind I would simply remove all of the items on that page from the formBackingObject. This would also allow you to go "backwards" to the previous page and deselect options as well.

    Another approach would be to instrospect into each page, so have a setPage1(final Object[] objs), setPage2(final Object[] objs) etc. and only combine them all at the end of the workflow.

  6. #6
    Join Date
    Jan 2006
    Posts
    15

    Default

    Quote Originally Posted by yatesco
    Good point.
    you make me feel smart

    thanks for all the help, i hope to be able to run with it from here. in my book you are the professional resident when it comes to checkboxes!

  7. #7
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    Another option is to just create 2 properties in your command object, e.g. something like:

    String[] selectedCheckboxesForPage1, and
    String[] selectedCheckBoxesForPage2.

    Then you don't have to worry about juggling the values that should be present based on whatever page you're on.

    You would still probably have to split up and recombine the lists when loading/saving the page respectively.

  8. #8
    Join Date
    Jan 2006
    Posts
    15

    Default

    unfortunately, the number of pages varies

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •