Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Creating clone of FormItem to resolve instability related to formitem re-use

    Hi,

    We were experiencing incredibly unstable behaviour in a DymanicForm, when we realized that it was almost certainly related to the warning message below:

    FormItems cannot be re-used with different DynamicForms

    The post in the smartclient forum described this issue for us well. (http://forums.smartclient.com/showthread.php?p=46822)

    So, we now need to implement the suggestion stated in the above forum thread by one SmartGWT developers (who I don't think works for Isomorphic). His comment is reprinted below:

    "Create a helper method that returns new instances of the same FormItem definitions instead."

    However, we did search to see if there were some easy "clone" method for a FormItem, but there doesn't seem to be one.

    So, we're about to write a routine which checks what type of FormItem an object is (e.g, is it a textitem etc.), then try to copy all the attributes using the "getAttributesAsMap" method, and then re-add any handlers (eg., blurhandlers etc). etc.

    However, this seems like extra error-prone code. Is there an easier/better SmartGWT way to "clone" a FormItem? ie some sort of "clone" / deepcopy procedure? (The other reason creating our own method is arguably not ideal is that a SmartGWT developer doesn't necessarily know all the private FormItem properties that ought to be copied over and may therefore introduce very unstable/unexpected behaviour.)

    Thanks in advance for your thoughts.

    Further operational details are below:

    ========
    OS: Windows XP Pro
    IDE: MyEclipse 9.0 with Google Plugin for Eclipse (2.3.1)
    SmartGWT EE 2.4
    Browwer: Mozilla Firefox 4.0.1
    GWT SDK: 2.2
    Sun JDK 1.6.0_13
    Last edited by gsaxena; 12 Jul 2011, 07:11.

    #2
    Why are you trying to reuse a FormItem instance in multiple places? If they share a configuration, create a subclass and use it.

    Comment


      #3
      We need to modify the dynamic form to add new formitems that are determined during runtime. (It so happens that these new formitems are setionitems, but I don't think that's relevant to this discussion.)

      So, to add new formitems (ie sectionitems) to the existing dynamicform, we were creating a new array of formitems (let's call it newArrayFormItems) and adding the new formItems (ie the sectionItems) to this newArrayFormItems as well as adding the old/original formitems. Then, we called:

      frmProcessUI.setFields(newArrayFormItems);

      This worked, but it created the very unstable behaviour as well as the warning message:

      --> "FormItems cannot be re-used with different DynamicForms"

      So, to the best of our knowledge/understanding, we need to create a COPY of the original formitems before we add them to the newArrayFormItems. (If "creating a subclass" helps this problem, as you mentioned in your post, could you please elaborate on what you mean by that -- we were not clear on how that would help and/or what you meant by that.)
      Last edited by gsaxena; 12 Jul 2011, 08:20.

      Comment


        #4
        Ah. Adding fields to a form has been addressed in the forum many times. This is not a recommended method. It would be better to create all your form items and apply them to setFields rather than using existing fields again. You can retain values as needed but always create new form items for any call to setFields.

        The other suggested method is to create all fields needed and hide/show the ones that the user should see.

        Additionally, you can always put multiple forms in a layout such that the result looks like a single form to the user and therefore add/remove "sections" as needed. If they share a DataSource record use a ValuesManager to tie them together.

        Comment


          #5
          Create a helper method that returns new items. Do not attempt to clone them, that's harder.

          Comment

          Working...
          X