Announcement

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

    #16
    ic,cheers.

    Comment


      #17
      Hi Blama,

      Can you please see if I am on the right track.

      I created the ds.xml files which have FK relation in my database. Now I have this CusNeiGroupDS.ds.xml file which I wan to use to populate my listgrid data from these tables.Can you please have a look at them and give me your feedback. I am new to smartgwt.Please bear with me.

      cheers
      Zolf
      Attached Files

      Comment


        #18
        this is the table relationship I have in my DB.see attachment. the PK field name I have given them the same name as it is in my DB table.
        Attached Files

        Comment


          #19
          Hi Zolf,

          yes, looks good.
          Now you can include the "<field name="..." includeFrom="DSname.fieldname"> in your province-DS.

          Make also sure to include all the *.ds.xml in your call to DSLoader in you main html-file. And please make sure that the three attributes (primaryKey, foreignKey, includeFrom) are supported in 3.0p.

          Once you think it is working it is always best to look at the generated SQL and compare it to what you expected.

          Perhaps also interesting in this context:

          If you are testing/developing a new application, I'd definitely use the most recent 4.1p or 5.0p build with a recent GWT version (2.6.1, not 2.7.0 yet). Isomorphic will definitely tell you so once you come up with a bug report.

          Best regards,
          Blama

          Comment


            #20
            Now this is the datasource file CusNeiGroupDSds.xml which I am calling from my listgrid to populate the listgrid. But I don't know how to include those 5 ds.xml file here. any help will be appreciated.


            Code:
            <DataSource ID="CusNeiGroupDS" serverType="sql">
            	<fields>
            		<field name="id" type="integer" primaryKey="true"/>
            		<field name="provincename" title="province" type="text" />
            		<field name="capital" title="capital" type="text" />
            		<field name="code" title="code" type="text" />
            		<field name="telcode" title="telcode" type="text" />
            		<field name="taxcode" title="taxcode" type="text" />
            		<field name="countyname" title="county" type="text"/>
            		<field name="district" title="district" type="text" />
            		<field name="city" title="city" type="text"  />
            		<field name="zone" title="zone" type="text" />
            		<field name="neighbour" title="neighbour" type="text"  />
            		<field name="taxcodecity" title="taxcodecity" type="text" />
            		<field name="fdocode" title="fdocode" type="text"  />
            		<!-- <field name="countCustomer" title="countCustomer" type="int" /> -->
            	</fields>
            </DataSource>

            Comment


              #21
              Hi zaj,

              the DS are loaded to the client in you main html file. Search it for DataSourceLoader and amend the list. In the ds.xml you gave you have to add:
              • the tableName like discussed with Isomorphic earlier.
              • A field like
                Code:
                <field name="myNameForCountynameField" title="County Name" includeFrom="countyDS.countyname" />
                <field name="myNameForDistrictnameField" title="District Name" includeFrom="districtDS.districtname" />

              If your DS name is really CusNeiGroupDS (and not provinceDS like in the file you gave), make sure to adjust the FK-attribute linking to this field.

              Best regards,
              Blama

              Comment


                #22
                I changed my CusNeiGroupDS.ds.xml file to reflect those datasource. But I get error.

                javax.servlet.ServletException: DataSource 'CusNeiGroupDS' failed to load due to an exception on the server:
                DataSource CusNeiGroupDS includes fields from DataSource provinceDS but we cannot establish a direct or indirect relation between those DataSources. You must specify foreignKey field(s) on the including DataSource (CusNeiGroupDS) that either express a direct relationship to provinceDS, or express an indrect relationship via one or more intervening tables

                I call this datasource like so
                Code:
                  listGrid.setDataSource(DataSource.get("CusNeiGroupDS"));
                Code:
                <DataSource ID="CusNeiGroupDS" serverType="sql">
                	<fields>
                		<field name="id" type="integer" primaryKey="true"/>
                		<field name="provincename" includeFrom="provinceDS.provincename" />
                		<field name="capital" includeFrom="provinceDS.provincename" />
                		<field name="code" includeFrom="provinceDS.provincename" />
                		<field name="telcode" includeFrom="provinceDS.provincename" />
                		<field name="taxcode" includeFrom="provinceDS.provincename" />
                		<field name="countyname" includeFrom="countyDS.countyname" />
                		<field name="district" includeFrom="districtDS.districtname" />
                		<field name="city" includeFrom="cityDS.cityname" />
                		<field name="zone" includeFrom="zoneDS.name" />
                	</fields>
                </DataSource>
                in my html file I have declared those ds files
                <script src="builtinds/sc/DataSourceLoader?dataSource=CusNeiGroupDS,provinceDS,countyDS,districtDS,cityDS,zoneDS"></script>
                Last edited by zaj; 15 Dec 2014, 03:15.

                Comment


                  #23
                  Your <script ... is correct. Does "provinceDS" have a foreignKey to "CusNeiGroupDS"? The error message is clear here, isn't it? The framework has to be able to build the tree structure in order to generate the joins.
                  CusNeiGroupDS is still missing the tableName-attribute.

                  Comment


                    #24
                    you see I have created this CusNeiGroupDS.ds.xml file and it is not a table in my database. It is just a file I created where I am trying to collect all the data from those different datasource/tables and use this CusNeiGroupDS to populate my listgrid.

                    Comment


                      #25
                      Well, it won't work this way. You gave a field with fieldname="id" which clearly belongs to this DS.
                      What should be the PK from a logic point of view?
                      Should be zoneDS.id IMO.

                      Why don't you use zoneDS for collecting?
                      Or create a copy of zoneDS as zoneDS1, load it, amend the fields and use this one.

                      Or do this instead of copy:
                      Code:
                      <DataSource ID="[B]zoneDS1[/B]" serverType="sql" tableName="zone" inheritsFrom="[B]zoneDS[/B]">
                      	<fields>
                      		...only includeFrom fields
                      	</fields>
                      </DataSource>
                      Best regards,
                      Blama

                      Comment


                        #26
                        PS:
                        If the aim is to edit fields in the ListGrid, it should be clear that includeFrom fields can't be edited (because of update anomaly). If you want to edit e.g. countyDS, you have to have a ListGrid with countyDS as DataSource.

                        Comment


                          #27
                          Hi Blama,

                          thanks so much for your cooperation. you made so many concepts clear which I was not sure about.
                          1. so,datasource has to be a table in my database.correct??. it cannot be on its own.
                          2. the field name has to be same as the column name or it can be different.
                          3. take this scenario where in my listgrid I give the name to a listgridfield as zone,like so. ListGridField zone = new ListGridField("zone");

                          but in my zone.ds,xml the field name is "name"(the name of the column in the zone table). now how do I correlate these together.


                          appreciate your help!!

                          cheers
                          Zolf
                          Last edited by zaj; 15 Dec 2014, 21:54.

                          Comment


                            #28
                            Hi zaj,

                            about 1) I'm not sure. Client-Only DataSources should be an exemption from this rule of thumb. Generally speaking I think that every "normal" DS is backed by one table in the DB. Note that many DS can be backed by the same table (tableName-attribute in the DataSource-tag)

                            2) No, can be different. See DSField.nativeName. It defaults to DSField.name.

                            3) See above.
                            The DSField.name is the only thing relevant when talking about client/server communication. Actually the DB-details are hidden from the client as good as possible. Open your browsers F12 tools and have a look at the result from the DataSourceLoader-call and compare it to your .ds.xml files. You'll notice that information relevant only for the server is stripped.

                            You should really read the serverds-docs just to get a feeling for the possibilities and definitely the Quick Start Guide, especially the chapters on data binding.

                            Best regards,
                            Blama

                            Comment


                              #29
                              Thanks for your feedbacks.I will definitely go through that serverds-docs.
                              One last question,
                              I have this Customer table and Neighborhood table. The Customer table has the Neighborhood ID as FK in it. Now I have this datasource called neighbourDS_1.ds.xml and using your instruction I managed to get all the fields I need to display in the listgrid. one column which I need is the count of customers in each Neighborhood.

                              Below is my datasource which I am using in my listgrid. The problem is the last field where I am trying to sum the customer. also I get this error. I know the error is related to those two table relationship. I don't know how to tell this neighbourDS_1.ds.xml that customer DS has a FK relationship with Neighborhood. One possible way is to use the customer table as the datasource table instead of neighbourhood. Just want to know is there some way to call from the child (neighbourhood) to parent(customer).

                              Code:
                               
                              === 2014-12-16 13:23:28,931 [3-24] ERROR DataSourceLoader - BaseServlet Global Exception
                              javax.servlet.ServletException: DataSource 'neighbourDS_1' failed to load due to an exception on the server:
                              DataSource neighbourDS_1 includes fields from DataSource CustomerDS but we cannot establish a direct or indirect relation between those DataSources.  You must specify foreignKey field(s) on the including DataSource (neighbourDS_1) that either express a direct relationship to CustomerDS, or express an indrect relationship via one or more intervening tables
                              Code:
                              <DataSource ID="neighbourDS_1" serverType="sql" tableName="neighbourhood" inheritsFrom="neighbourDS">
                              	<fields>
                              		<field name="provincename" includeFrom="provinceDS.provincename" />
                              		<field name="capital" includeFrom="provinceDS.capital" />
                              		<field name="code" includeFrom="provinceDS.code" />
                              		<field name="telcode" includeFrom="provinceDS.telcode" />
                              		<field name="countyname" includeFrom="countyDS.countyname" />
                              		<field name="district" includeFrom="districtDS.districtname" />
                              		<field name="city" includeFrom="cityDS.cityname" />
                              		<field name="taxcodecity" includeFrom="cityDS.taxcodecity" />
                              		<field name="fdocode" includeFrom="cityDS.fdocode" />
                              		<field name="zone" includeFrom="zoneDS.zone" />
                              		<field name="printName"  includeFrom="CustomerDS.printName" includeSummaryFunction="sum"/>
                              	</fields>
                              </DataSource>

                              Comment


                                #30
                                Hi zaj,

                                that an interesting question.

                                I assume you have a FK in the ds.xml from
                                customerDS.ds.xml -> neighbourDS.ds.xml.
                                Now you need the same as
                                customerDS.ds.xml -> neighbourDS_1.ds.xml.

                                I don't know if the foreignKey-attribute in customerDS.ds.xml can be written as list
                                foreignKey="neighbourDS.id, neighbourDS_1.id". That's one for Isomorphic.

                                Workaround could be a new field in customerDS.ds.xml similar to:
                                <field name="neighbour_id2" nativeName="neighbour_id" foreignKey="neighbourDS.id" />

                                Regarding your includeSummaryFunction:
                                Is it supported in your version? From the blog entry I linked I don't think so, although I don't have the 3.1p docs.
                                Either switch to 4.1p+ or do the aggregation in a DB-view, generate a DS for it and join the DS in your .ds.xml.

                                Best regards,
                                Blama

                                Comment

                                Working...
                                X