Announcement

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

    DynamicForm DataSource with ForeignKey

    I've setup ListGrid objects that use a DataSource and they work great with the ForeignKey setup, however when I try to use the same DataSource in a DynamicForm the drop down for the ForeignKeys only show the value field not the display field.

    ListGridWidget (code)
    Code:
    public CategoryListGridWidget(Criteria c) {
    	setCanEdit(true);
    	setAutoSaveEdits(false);
    	setShowFilterEditor(true);
    	setDataSource(new CategoryListGridDS());
    	setAutoFetchData(true);
    	setAlternateRecordStyles(true);
    	setShowAllRecords(false);
    	setDataPageSize(10);
    	if(c != null) {
    		setInitialCriteria(c);
    	}
    	setWrapCells(true);
    }
    Example Datasource Field (code (small snippet example with one field))
    Code:
    public CategoryListGridDS() {
    	...
    	intField = new DataSourceIntegerField("cgytyp");
    	intField.setEditorType(new CategoryTypeSelectItem(time));
    	name = "categorytypeds_"+time;
    	intField.setForeignKey(name+".cgytyp");
    	intField.setCanEdit(true);
    	addField(intField);
    	...
    }
    Example SelectItem (code)
    Code:
    public CategoryTypeSelectItem(long id) {
    	CategoryTypeListGridDS ds = new CategoryTypeListGridDS();
    	ds.setID("categorytypeds_"+id);
    	setValueField("cgytyp");
    	setDisplayField("dsc");
    	setEmptyPickListMessage("No data in table");
    	setPickListWidth(450);
    		
    	ListGridField idField = new ListGridField("cgytyp");
    	ListGridField dscField = new ListGridField("dsc");
    	setPickListFields(idField, dscField);
    		
    	setOptionDataSource(ds);
    	setAutoFetchData(true);
    }

    Form (using the same CategoryListGridDataSource above)
    Code:
    CategoryListGridDS cglds = new CategoryListGridDS();
    final DynamicForm df = new DynamicForm();
    if(c != null) {
    	df.setInitialCriteria(c);
    }
    
    df.setDataSource(cglds);
    df.setAutoFetchData(true);

    #2
    Can this be done so it will show FK in a Dynamic Form?

    If this can't be done, just would like to know or if it can be what I'm doing wrong since it's the same DS just being used in a ListGrid vs the DynamicForm.

    Thank you,

    Comment


      #3
      Yes, this can be done, however try doing it without using the setEditorType() API and a SelectItem subclass, there are some issues with that API that haven't been fully worked out yet.

      Comment


        #4
        Thank you for the reply

        How would I do that if I don't have the SelectItem subclass that is using a Datasource.

        Is there another way, would it have to be static?

        Thank you for your help, much appreciated.

        Comment


          #5
          Also stuck on this issue

          Could we have a follow up on this issue. I have the same problem.
          I am using SmartGWT 1.3, Google Web Toolkit 1.7.1 SDK Bundle for Eclipse 3.5, I have run the app in Hosted Mode and Compile/Browse mode.
          I have tested separately the SelectItem, without the foreign key stuff and it works, fetches the data properly form the server.

          I am using a RestDataSource with out of the box functionality (no overrides).

          Comment


            #6
            Create a SelectItem as part of the form definition rather than doing it via setEditorType().

            Comment


              #7
              If I just attach the datasource to the dinamicform the fields are created automatically. If I declare the SelectItem in the form definition I will be forced to declare all the rest of the fields and I will loose this automatic feature.
              Am I missing something?

              Comment


                #8
                You can set useAllDataSoureFields to cause fields to still be generated based on the DataSource, where your component-specific field definitions act as overrides and additional fields.

                Comment


                  #9
                  Thank you

                  That made my day. It was exactly what I was looking for.
                  Thank you for your help. Again, this framework is awesome.

                  Comment


                    #10
                    Please supply an example...I'm still not sure how this works

                    Originally posted by Isomorphic
                    You can set useAllDataSoureFields to cause fields to still be generated based on the DataSource, where your component-specific field definitions act as overrides and additional fields.
                    Could you supply an example using the example code I have in the first post or maybe another example using a DataSource and the ForeignKey?

                    Thank you,

                    Disregard after some trial and error I seem to have it working.

                    Thank you very much.
                    Last edited by gcstang; 10 Dec 2009, 15:20.

                    Comment


                      #11
                      Ok I have that working but now I have a new issue the hides no longer work...

                      Thank you for any help you can send my way.

                      My Versions:
                      SmartGWT 2.0
                      GWT 2.0

                      I'm adding two dynamic forms to a layout like :
                      Code:
                      DynamicForm mbrAddrForm = new DynamicForm();
                      
                      //First I had all my fields since I only want a few to show
                      MemberAddressListGridDS mbradrlds = new MemberAddressListGridDS();
                      DataSourceField[] flds =  mbradrlds.getFields();
                      for (int i = 0; i < flds.length; i++) {
                      	flds[i].setHidden(true);
                      }
                      		
                      //Have to set Editable to allow change from the DS and unhide or they're 
                      //  not added to the Form
                      mbradrlds.getField("mbrid").setCanEdit(true);
                      mbradrlds.getField("mbrid").setHidden(false);
                      mbradrlds.getField("adrseq").setCanEdit(true);
                      mbradrlds.getField("adrseq").setHidden(false);
                      //etc...
                      
                      mbrAddrForm.setDataSource(mbradrlds);
                      mbrAddrForm.setUseAllDataSourceFields(true);
                      
                      //I set my default values and hide a few fields after setting them
                      
                      mbrAddrForm.getField("mbrid").hide();
                      mbrAddrForm.getField("adrseq").setValue(0);
                      mbrAddrForm.getField("adrseq").hide();
                      mbrAddrForm.getField("adrtyp").setValue(1);
                      mbrAddrForm.getField("adrtyp").hide();
                      
                      //Now there is a bug in the DS API when using them in a form so I have to 
                      // redeclare them in here or they won't show more than the fkey column
                      //  I create SelectItem's for the two I need one is for State the other for
                      //  Country
                      
                      
                      //If I remove the mbrAddrForm.setFields() the hides above work fine
                      // If I add this line they're ignored, is there a way around this?
                      SelectItem state = ....
                      SelectItem cntry = ...
                      
                      mbrAddrForm.setFields(state, cntry);
                      (last comment from code above)
                      If I remove the mbrAddrForm.setFields() the hides above work fine
                      If I add this line they're ignored, is there a way around this?


                      Thank you for your help.

                      Comment


                        #12
                        I found a solution or at least a work around...

                        I had to implement the following :

                        As per my previous post I still hide all from my DS than set editable and hidden to false on the fields I want in my final DynamicForm.

                        I set my DataSource to the one for this form and setUseAllDataSourceFields(true);

                        I than set my initial values and make some of those form items visible or not, as needed once I've set my values like this :

                        Code:
                        mbrAddrForm.getField("adrseq").setValue(0);
                        mbrAddrForm.getField("adrseq").setVisible(false);
                        I also had an issue with Colliding ID's so I had to also add this to every FormItem :
                        Code:
                        mbrAddrForm.getField("adrseq").setAttribute("ID", "adrseq");
                        I had to create my SelectItems in this Class since the DataSource has issues on Forms with Foreign Keys and also apply the setAttribute("ID", name);

                        And finally setFields on all Fields I want in my final form because if I only add the SelectItems that override the fields in my original DataSource than the fields I want to hide above are ignored and displayed.

                        Maybe this isn't the correct way but due to the issues in the API this is the only way I've found that works.

                        Isomorphic (or anyone) if you have any guidance or changes I should attempt to make this easier it would be appreciated.

                        Thank you,

                        Comment


                          #13
                          You seem to be radically overcomplicating things..

                          If you want a few specific fields to show, just specify those on the form and do not set useAllDataSourceFields.

                          If you want basically all fields to show, but you want to specialize how they appear, set useAllDataSourceFields, and create item definitions for just the items you want to specialize.

                          In both cases FormItems are matched to DataSource fields by name.

                          Comment


                            #14
                            Unfortunately I need the FK's Lookups...

                            Originally posted by Isomorphic
                            You seem to be radically overcomplicating things..

                            If you want a few specific fields to show, just specify those on the form and do not set useAllDataSourceFields.

                            If you want basically all fields to show, but you want to specialize how they appear, set useAllDataSourceFields, and create item definitions for just the items you want to specialize.

                            In both cases FormItems are matched to DataSource fields by name.
                            Earlier in this thread we concluded(I believe) that FK's from a DataSource in a form don't show correctly so we need to override them and in doing so have to use "useAllDataSourceFields" in order to do that, right?

                            Comment


                              #15
                              No, unrelated. If you want to override anything on a per-field basis, you just specify a FormItem for the field and put properties there. useAllDataSourceFields controls which fields are present and does not affect how overrides for a specific field work.

                              Comment

                              Working...
                              X