Announcement

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

    Datasource-bound custom Calendar event editing

    I am using a datasource-based Calendar, and would like to include additional fields (from my datasource) in the EventEditor and EventDialog. Those additional fields would be presented as drop-down lists (from SelectItem), and, since the values in the calendar datasource are simply keys (e.g. “personID”, “activityID”), they would need to be mapped to a more friendly values. Reading the documentation, it would seem like OptionDataSource in the SelectItem would be perfect for that task, but a LinkedHashMap (with setValueMap) could also be used. (I tried both, and neither seemed to work properly.)

    I started off by trying to alter the Calendar “Custom Event Editing” showcase sample to use OptionDataSource-bound SelectItems for my custom fields. (See CalendarBug.java below, which uses, for simplicity, a RestDataSource with file activities.xml.) I’ve attached the code that I have so far… I’m using SmartGWT 2.4, GWT 2.3, and Chrome/Firefox/IE8. It doesn’t work, with a couple of oddities:

    1) After adding my calendar datasource-bound fields via setEventEditorFields, the “name” property of the Item seems to disappear. The simple workaround for that is to set it again after the setEventEditorFields call. But maybe that workaround implies that I’m missing something.

    2) In debug/hosted mode (on Eclipse): The field that I attempted with the LinkedHashMap properly converted the key to the friendly name, but the drop-down list does not display any of the other options.


    3) In debug mode (on Eclipse): The field that I attempted with the OptionDataSource (“activityID” in the EventEditor) displayed as a combo-box, but did not convert into the display value. Actually, it did not even request the OptionDataSource at all, based upon looking at the Firebug logs. The Developer Console shows an error:

    Code:
    19:16:09.752:MUP3:WARN:SelectItem:isc_SelectItem_8:fetchData() called for a non-databound pickList. Ignoring
    And then another error when clicking on the dropdown list:

    Code:
    19:17:18.317:MUP0:WARN:Log:TypeError: Cannot call method 'getID' of null
    4) However, in release/web mode, the drop-downs do not show up at all, and the Item is simply displayed as a text item. This means that key values are shown, and not translated into friendly names. It is odd that debug mode behavior does not match release mode.

    5) On the nightly build (SmartGWT 2.5 2011-06-25), the EventDialog doesn’t even show up, as when I try to open it on an event, I get a large messagebox (see attachment “nightlybuild_eventmessage.txt”). It looks like I can’t have any SelectItem on either of the EventEditor or EventDialog windows. (I’m less concerned about this, of course, as it is a “nightly build” after all.)


    So... Am I missing something obvious? (Other than brevity?) Is there a bug somewhere in the Calendar EventDialog / EventEditor functionality? Is there a better way of doing this?

    Thank you, in advance.
    Attached Files

    #2
    3 is a bug. the workaround is to use setAttribute("optionDataSource",dataSourceName)

    Comment


      #3
      Yes, you are correct, atomatom. Line 94 of the my code in CalendarBug.java should have had setAttribute("optionDataSource"...) rather than setAttribute("OptionDataSource"...) in it.

      Still, #4 is the one that is killing me... I don't know how to get release/web mode working, and that really is the point...

      Comment


        #4
        Sounds like it might be crashing. Have you used Firebug with Script turned on. Check to see if there are any javascript exceptions.

        Likewise, you might want to see if there are any warning/errors in hosted/Developer mode.

        Finally, make sure you recompile and refresh your browser.

        Comment


          #5
          Also, no idea if this is your problem, but you might want to call setFields after you're finished modify the fields.

          SmartGWT does not use your field instances - it copies the properties into its own instance. There is a good blog post explaining this by david, but I can't find it right now.

          Comment


            #6
            Okay, I think that I figured it out. (Again, using SmartGWT 2.4.) As atomatom mentioned, SmartGWT copies the field instances... I had been configuring my fields _after_ calling setEventEditorFields. If I were to simply set the datasources and such _before_ calling setEventEditorFields, it all works out.

            With one exception... Chrome in hosted/dev mode. For some reason, I get an error:

            Code:
            19:17:10.546 [ERROR] [calendarbug] 19:17:10.531:MUP9:WARN:DynamicForm:isc_DynamicForm_0:[Class TextItem] form item defined with no 'name' property - Value will not be saved. To explicitly exclude a form item from the set of values to be saved, set 'shouldSaveValue' to false for this item.
            The workaround for that is to reset my fields' names, via setName(), _after_ the setEventEditorFields. (I suspect that is what led me down this rabbit's hole... I did most of my dev with Chrome.) With that, IE8/Firefox/Chrome work in both hosted and web mode.

            Whew! I'll attach the updated java file, for sake of completeness. Thanks helping out, atomatom.
            Attached Files

            Comment


              #7
              Also for completeness, this code works fine with the nightly build SmartGWT 2.5 2011-06-25.

              Sigh. Not a bug. And maybe this thread will help someone avoid the same mistakes as me.

              Comment


                #8
                About Chrome dev mode - see FAQ: it's broken due to something Google needs to fix.

                Comment


                  #9
                  This is a pretty excellent article about how customizing ListGrid/Calendar editors works and some gotchas:

                  http://smartclientexperience.wordpre...tom-formitems/

                  If it makes you feel better you're not alone. Many people get hit with how field customization works (I have several scars). I now appreciate why SmartClient works that way, but it'd be really nice if there were a more friendly/less footshooty way of customizing forms. The trouble is finding a balance of speed vs complexity.

                  Comment

                  Working...
                  X