Announcement

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

    why does setEditorValueMapFunction return String[]???

    Hi,

    For the past 2 days, I have been trying to make one thing work with the ListGrid and it's truly unbelievable. Here's the problem i am facing:

    I have a listgrid that contains two inter-dependent dropdown lists. column 1 has a list of owners, while column 2 has a list of divisions. When I select an owner, the list of divisions in column 2 should refresh to contain only the divisions of the selected owner.
    In my design, i have a DS for the owners and a DS for the divisions.

    I tried several things, but the 3 main things are:

    A. I tried making the owners' dropdown as a SelectItem and i put an onChange handler in order to do a re-fetch on the divisions' DS. The fetch is taking place with the right criteria, however the selectItem does not refresh (or does not invalidate its cache). I have tried several tweaks, but couldn't make it work.

    B. I tried the method used by the ShowCase, under "Dependent Selects(Grids)". And here's the big surprise. The method works only with a ValueMap, and it suggests that we set an EditorValueMapFunction, which is an interface that has one method to implement: getEditorValueMap which returns a String[]. So, in other words, we can only return a list of options (either values or displays, but not both), instead of a ValueMap. So, how can i have divisions showing a certain display, while having a different value in the database? Moreover, do i have to go though my DS's data and fill it into a Map in order to make use of this?

    C. I even tried using the method suggested in ShowCase for the form, but i couldn't tweak it to work on a listgridfield.

    To be honest, it feels almost impossible to manipulate anything in a Listgrid. I am starting to worry about future problems, like the ability to have a different picklist on each row in a listgrid, based on the value of one of its columns, for example. Also, the ability to force only a set of options in a selectItem when inserting a record, while having more options when editing a record.

    Sadly, these many problems are making my boss rethink our decision to build a software based on smartGWT. And the worst part is that we were half-way through developing it.

    Any help is appreciated.
    Thanks in advance.

    #2
    Nicole there's no fundamental issue with SmartGWT here, this is just a matter of working out SmartGWT equivalents for existing SmartClient APIs. You can see both local and databound dependent selects in this SmartClient sample with very elegant syntax:

    http://www.smartclient.com/index.jsp...pendentSelects

    With the existing APIs your approach (A) is closest. Most likely the problem is that you are calling DataSource.fetchData(), which is documented as not having any affect on visual components, and so would not cause the SelectItem to refresh. Instead, form a Map from the returned records and call setEditorValueMap() with that.

    Comment


      #3
      B. I tried the method used by the ShowCase, under "Dependent Selects(Grids)". And here's the big surprise. The method works only with a ValueMap, and it suggests that we set an EditorValueMapFunction, which is an interface that has one method to implement: getEditorValueMap which returns a String[]. So, in other words, we can only return a list of options (either values or displays, but not both), instead of a ValueMap. So, how can i have divisions showing a certain display, while having a different value in the database? Moreover, do i have to go though my DS's data and fill it into a Map in order to make use of this?
      I've changed the return type of EditorValueMapFunction to be a Map in SVN.

      Sanjiv

      Comment


        #4
        Thanks Sanjiv. I'll download the latest nightly build and try it.

        Comment


          #5
          fyi the Dependent Selects (Grid) sample has been updated to include an example of dependent Select Items with remote data.

          You can find the updated sample code here.

          Comment


            #6
            I tried it, but the selectItem still doesn't refresh!

            Originally posted by Isomorphic
            With the existing APIs your approach (A) is closest. Most likely the problem is that you are calling DataSource.fetchData(), which is documented as not having any affect on visual components, and so would not cause the SelectItem to refresh. Instead, form a Map from the returned records and call setEditorValueMap() with that.
            Hi Isomorphic,

            I tried your above suggestion: Instead of just doing a ds.fetch(), i am now looping through the fetched data and filling them in a Map. Then, using setEditorValueMap, i set the map to my ListGridField. But, still, the field doesn't refresh with the new data.

            Any idea why?
            Isn't there any method on SelectItems or ListGridFields that could act as an equivalent to invalidateCache???

            Please let me know.
            Thanks.

            Comment


              #7
              If your still having trouble with your manual data fetching, you probably want to just copy the new Databound Dependent Selects referenced above.

              Comment


                #8
                why doesn't the setValueMap work, except the first time?

                Hi,

                Thanks for pointing me to your example, but I don't want to redo it with this picklist filter criteria method. I want to do a remote fetch, not local filtering.

                What i want to understand (i'm wondering why noone is answering this question) is why isn't there any invalidateCache method on the listgrid's select item? I fumbled into the js code and found that there is in fact a fetchData method that could take a boolean parameter that drops the cache. I implemented the native java method for it on my form selectitem. What i'm doing now is that i fetchData on my ds, then in the onsuccess, i call this native java method which clears the cache. This worked in showing the refreshed results on the visual item, however in some cases on the listgrid (very random) it doesn't work and i still haven't found out why. moreover, even when the list does refresh, if i choose an option, the option doesn't appear in the field until i click outside the currently edited row. and when i do, it appears but always with a validation error "not valid option".

                So, i ended up changing this whole method once again and trying to loop through the ds's results, filling them in a map, and setting it as a value map.
                but, it doesn't refresh! i understand that the fetchData does not refresh visual items, but shouldn't setValueMap do so??

                Honestly, handling things in the listgrid feels like a nightmare. Nothing ever comes out as expected and it's always far more complicated than the form.

                Appreciate your answers and any help you can provide because this is very urgent.

                Thanks.

                Comment


                  #9
                  Nicole the example already does remote fetch, not
                  local filtering. Please look it over very carefully and read the related documentation. You are making things more complicated than they
                  need to be by looking for means of manually controlling a
                  process which is already doing what you want.

                  Comment


                    #10
                    Hi,

                    Thanks Isomorphic for your reply, but as i mentioned before, noone has yet replied to my question about the invalidateCache. Nor about why it's not refreshing visually when i setValueMap. Shouldn't these be working, regardless of why i need them and whether or not i am redoing something that's already done?

                    Anyway, i did try the method in the example you pointed me to. And in debugging, i could clearly see that the server-side fetch is only being called when the DS is first initialized. the filtering is not occurring server-side. the db select is not being executed more than once and retrieving all the results (unfiltered). this is why i said it is local filtering.

                    Moreover, as i mentioned above, even why i tried this method, the selected option does not immediately appear in the listgridfield. it only appears after i click outside the currently edited row. what i did to fix this is that i added an onchangedhandler for the selectitem and, in it, i manually set the listgridfield's value. i think this is a bug, but u might want to double check.

                    Thanks again.

                    Comment


                      #11
                      OK, this is getting kind of silly, but one more time: the example does do remote fetching and remote filtering, by way of a DataSource. In the SmartGWT showcase, all the DataSources are client-only so that the showcase can be deployed without the need for a server or database to be set up. But if you look in the RPC tab of the Developer Console, you will find the requests and responses reflecting how the form controls are interacting with the DataSource.

                      If you want to see it with a DataSource that happens to actually connect to SQL, see the corresponding SmartClient sample. Exactly the same pattern of accessing the DataSource is happening in each case.

                      As far as your attempts to invalidateCache and setValueMap, no, you should not expect that calling these methods at various times would have any effect other than breaking the built-in behavior. The built-in behavior is not expecting you to jump in and clear out data it has just retrieved, for example.

                      As far as the issue you're seeing, try the running sample, if you don't see it there, remove your attempts to manually tweak the interaction until you see your version work like the sample does.

                      Comment

                      Working...
                      X