Announcement Announcement Module
Collapse
No announcement yet.
Form and subform relationships Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form and subform relationships

    Hello all

    Actually I'm having trouble to understand the kinds of FormModel

    I need to make a form that is divided in two forms (in the same page): each one represent different objects of my business.

    I was takin' a look at some topics of the forum and saw examples of some classes that I didnīt find on the springrichclient_0.2.1 jars: NestingFormModel and CompoundFormModel

    But I saw HierarchicalFormModel, that seems to fit to my needs....The problem is that until now I donīt know how to use it well...

    If somebody already used this class or can explain the function of the FormModel classes I'll be grateful

    Regards

  • #2
    Hello manasouza,

    I'm not sure, if the HierachicalFormModel is the right solution for you. It depends on the type of the relation of your business objects.
    Usually the HierachicalFormModel is used for some kind of parent-child or master-detail relations.
    For instance the HierarchicalFormModel is used as FormModel for AbstractTableMasterForm and AbstractDetailForm. In the master table you
    have a list of business objects, e. g. products and in the detail form
    you have product details.
    Both models share their state (enabled/disabled, dirty) in a way, which is described in the api docs of the interface:
    http://spring-rich-c.sourceforge.net...FormModel.html

    If your business objects are independent from each other then the best solution for you is perhaps to simply create two separate forms with
    their own form models and place them onto one page.

    Hope this will help you.

    Bye,
    Torsten

    Comment


    • #3
      Mutilple forms

      Manasouza,

      I have three forms in one view. They are all tied together for validation, etc.

      What I did was
      1) create a inner 'wrapper' class that contains the three domain ojects.
      2) create a model on the wrapper class
      3) create children models from the wrapper model (ties them together)
      4) pass the models into the forms

      Wrapper Class
      Code:
         private class RoleWrapper {
            private DocHolder docHolder;
            private Role role;
            private SpecificRole specificRole;
            
            public RoleWrapper() {
               setDocHolder(new docHolder());
               setRole(new Role());
               setSpecificRole(new SpecificRole());
            }
            
            public RoleWrapper(DocHolder doc, Role role, SpecificRole specificRole) {
               setDocHolder(idoc);
               setRole(role);
               setSpecificRole(specificRole);
            }
            
            public DocHolder getDocHolder() {
               return docHolder;
            }
            
            public void setDocHolder(DocHolder docHolder) {
               this.docHolder = docHolder;
            }
            
            public Role getRole() {
               return role;
            }
            
            public void setRole(Role role) {
               this.role = role;
            }
            
            public SpecificRole getSpecificRole() {
               return specificRole;
            }
            
            public void setSpecificRole(SpecificRole specificRole) {
               this.specificRole = specificRole;
            }
            
         }
      Models and Forms
      Code:
      // create the wrapper object and create the model for it
      // the wrapper contains the various objects that make up this page
      RoleWrapper wrapperObject = new RoleWrapper();
      formModel = FormModelHelper.createFormModel(wrapperObject);
      
      // create child models FROM the wrapper model (required for validation/commit/rollback functionality)
      // note how the child model is tied to the wrapper members by name
      ValidatingFormModel docFormModel = FormModelHelper.createChildPageFormModel(formModel, DocForm.FORM_ID, "docHolder");
      ValidatingFormModel roleFormModel = FormModelHelper.createChildPageFormModel(formModel, RoleForm.FORM_ID, "role");
      ValidatingFormModel specificRoleFormModel = FormModelHelper.createChildPageFormModel(formModel, SpecificRole.FORM_ID, "specificRole");
      
      // form creation needs to take the model
      docPanel = new DocPanel(null, docFormModel);
      roleForm = new RoleForm(roleFormModel);
      tpaForm = new SpecificRole(specificRoleFormModel);
      David

      Comment


      • #4
        David and Torsten, thank you very much!

        With the explanation about HierarquicalFormModel I think itīs not really what I want Torsten, and my business objects are not independent from each other...

        So the solution provided by David, as it seems, fits to my needs (I didnīt tested it yet)

        Regards guys

        Comment

        Working...
        X