Announcement

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

    #16
    Is the only way to create a server side DataSource without creating XML and then calling DataSource.fromXML()?

    The undocumented (and probably out of API) method fromConfig looks like a possibility, but I've no idea what the arguments mean.

    Comment


      #17
      The only documented approach is fromXML(), yes.

      Comment


        #18
        Are there any factory methods that can help produce the XML or should I just make my own XML DataSource generating factory? It's pretty easy I guess since I just want simple fields.

        Comment


          #19
          I am still struggling to get this new API working. Could someone please point me if i am missing something? What i did is:

          1. Extended IDACall servlet and registered DynamicDSGenerator as below.
          public class MyCallServlet extends IDACall {
          public MyCallServlet (){
          super();
          DataSource.addDynamicDSGenerator(new MyDynamicDSGenerator(), "My");
          }
          }

          2. And my MyDynamicDSGenerator class looks like below.
          public final class MyDynamicDSGenerator implements DynamicDSGenerator {
          public DataSource getDataSource(String id, DSRequest dsRequest) {
          DataSource dataSource = null;
          if(id != null && id.startsWith("My")) {
          try {
          String xml = createMySearchDataSource(id, dsRequest);
          dataSource = DataSource.fromXML(xml);
          } catch (Exception e) {
          logger.log(Level.SEVERE, e.getMessage(), e);
          }

          }
          }
          }

          Now the problem cases are -
          If i mention datasource name in html boot strap using "DataSourceLoader?dataSource=" syntax and not include anything with that name under ds folder then i get "Unable to Load Exception"
          And if i provide a empty file for this datasource (MySearch) under /ds folder then it doesn't load fresh copy for the same datasource from server for every request it's being used.
          And if i don't mention datasource name in html boot strap but try to access the datasource in my code assuming that if it doesn't exists then SmartGWt will load it from server but it doesn't and i get NullPointerException.

          May i missing something? Kindly help.

          Thanks,
          Last edited by learn_smartgwt; 15 Feb 2011, 08:07.

          Comment


            #20
            Indicate version and browser, and show the complete server-side log for the request that ends in the exception, including the exception itself (do not trim anything). Always do this.

            Comment


              #21
              Originally posted by Isomorphic
              Indicate version and browser, and show the complete server-side log for the request that ends in the exception, including the exception itself (do not trim anything). Always do this.
              Thanks for response. I can't post server log due to sensitive information. But i would height appreciate and will try to find the issue myself if you can please guide me how to load & use dynamic datasource at client side.

              Below are my questions?
              1. Do i need to create a empty file with same datasource id under ds folder?
              2. Do i need to add this datasource id in html boot strap to load via DataSourceLoader?dataSource= syntax ? if not then how to make it available so DataSource.get() can create the instance from server?

              In my case subclassing to IDACall and register Dynamic generator works fine as i can see all the calls related to system as well as project ds going through this generator.

              I am using SmartGWt 2.4 eval version with IE 7 browser.

              Thanks again.

              Comment


                #22
                No empty file is required and you use the DataSourceLoader servlet normally.

                Other than that, we need logs to help - if you need confidential treatment of issue reports, that is available with Enterprise Support.

                Comment


                  #23
                  All,

                  I am using the eval smartgwtee 2.4. Tried 2.5 as well.

                  I followed the example of the earlier poster and have come to the same conclusions:
                  1) Unless at least a skeleton of a datasource id is loaded through the DataSourceServlet (from the initial html) file, the DynamicDSGenerator is never called! As such a null datasource is returned immediately from DataSource.get(dsName)

                  2) If the DynamicDSGenerator is registered as :
                  DataSource.addDynamicDSGenerator(new MyDSGenerator(), "PREFIX")
                  rather than:
                  DataSource.addDynamicDSGenerator(new MyDSGenerator())

                  it is never called!

                  I would like to suggest that Isomorphic provide a simple but complete example of DynamicDSGenerator in action that works (perhaps based on the BuiltinDS sample and the embedded HSQLDB)

                  In addition, we have seen much mention of DataSource.load(). We would like to suggest that it be made clear that
                  (1) this is a client side call and
                  (2) see a complete example of where this works.

                  Each time that we try make this call, we get a DataSourceServlet 'not loaded' error, when it is clear that the DataSourceServlet has been loaded (and works) as it has loaded datasources specified in the .html file.

                  Regards.

                  Comment


                    #24
                    Your assertions are definitively incorrect and many other users are successfully using this API. While a sample is on the way (no ETA), what you need to do if you think there's a bug is to produce a standalone test case. This will allow us to identify usage errors in your code, if any.

                    Comment


                      #25
                      @abbottk2000 - I would disagree with you. All wiring works fine if you do it write.

                      @Isomorphic - Either we are missing something on how to use the datasource at client side otherwise there is definetly something wrong with API. All works fine i can even see modified datasource at server side but client completely ignore it and uses the earlier loaded version.

                      I have replicated the issue in BuiltInDS example. Hope this will help to pin point the issue.
                      Attached Files

                      Comment


                        #26
                        You should all try logging your generated DataSource definitions - this "standalone test case" looks like it just generates an invalid one (multiple fields named the same thing).

                        Comment


                          #27
                          Originally posted by Isomorphic
                          You should all try logging your generated DataSource definitions - this "standalone test case" looks like it just generates an invalid one (multiple fields named the same thing).
                          I log generated DS to server console using following line in MyDataSourceLoader class.
                          System.out.println("Xml:" + stringBuffer.toString());

                          This is a working code. Generated datasource are completely valid.

                          Below is the logged datasource what is being generated at application load time - please note Name, Email & Salary fields are missing.
                          Code:
                          <DataSource    ID="employees"    serverType="sql"    tableName="employeeTable"    recordName="employee"    testFileName="/examples/shared/ds/test_data/employees.data.xml"    titleField="Name">    <fields>        <field name="EmployeeId"      title="Employee ID"     type="integer"  primaryKey="true"  required="true"/>        <field name="ReportsTo"       title="Manager"         type="integer"  required="true"                foreignKey="employees.EmployeeId"  rootValue="1" detail="true"/>        <field name="Job"             title="Title"           type="text"     length="128"/>         <field name="EmployeeType"    title="Employee Type"   type="text"     length="40"/>        <field name="EmployeeStatus"  title="Status"          type="text"     length="40"/>        <field name="OrgUnit"         title="Org Unit"        type="text"     length="128"/>        <field name="Gender"          title="Gender"          type="text"     length="7">            <valueMap>                <value>male</value>                <value>female</value>            </valueMap>        </field>        <field name="MaritalStatus"   title="Marital Status"  type="text"     length="10">            <valueMap>                <value>married</value>                <value>single</value>            </valueMap>        </field>    </fields><operationBindings><operationBinding operationType="fetch"><whereClause> Gender = 'male' </whereClause></operationBinding></operationBindings></DataSource>
                          And Below is the logged datasource what is being generated when you check a check box on screen and refresh the grid. Please note that Name, Email & Salary fields are available.
                          Code:
                          <DataSource    ID="employees"    serverType="sql"    tableName="employeeTable"    recordName="employee"    testFileName="/examples/shared/ds/test_data/employees.data.xml"    titleField="Name">    <fields>        <field name="EmployeeId"      title="Employee ID"     type="integer"  primaryKey="true"  required="true"/>        <field name="ReportsTo"       title="Manager"         type="integer"  required="true"                foreignKey="employees.EmployeeId"  rootValue="1" detail="true"/>        <field name="Job"             title="Title"           type="text"     length="128"/>         <field name="EmployeeType"    title="Employee Type"   type="text"     length="40"/>        <field name="EmployeeStatus"  title="Status"          type="text"     length="40"/>        <field name="OrgUnit"         title="Org Unit"        type="text"     length="128"/>        <field name="Gender"          title="Gender"          type="text"     length="7">            <valueMap>                <value>male</value>                <value>female</value>            </valueMap>        </field>        <field name="MaritalStatus"   title="Marital Status"  type="text"     length="10">            <valueMap>                <value>married</value>                <value>single</value>            </valueMap>        </field> <field name="Name"   type="text"     length="128"/> <field name="Email"   type="text"     length="128"/> <field name="Salary"   type="text"     length="128"/>    </fields><operationBindings><operationBinding operationType="fetch"><whereClause> Gender = 'male' </whereClause></operationBinding></operationBindings></DataSource>
                          Also please find the attached server log also.

                          Thanks,
                          Attached Files

                          Comment


                            #28
                            These logs show a successful SQL query executed by your dynamically generated DataSource, and your sample does not demonstrate the issue you're claiming.

                            You may have confused yourself because you previously were registering your DynamicDSGenerator only when IDACall is invoked. That's obviously too late since IDACall would typically be invoked after the DataSourceLoader servlet. This is why we suggest registering your DynamicDSGenerator via a servlet that has <load-on-startup> set (but after the Init servlet).

                            Comment


                              #29
                              Originally posted by Isomorphic
                              These logs show a successful SQL query executed by your dynamically generated DataSource, and your sample does not demonstrate the issue you're claiming.

                              You may have confused yourself because you previously were registering your DynamicDSGenerator only when IDACall is invoked. That's obviously too late since IDACall would typically be invoked after the DataSourceLoader servlet. This is why we suggest registering your DynamicDSGenerator via a servlet that has <load-on-startup> set (but after the Init servlet).
                              <b>
                              Thanks for prompt reply. You are right that's what my problem is it's working fine at server but client completely ignores updated(dynamically generated ds) datasource.
                              </b>

                              Please correct me if i am wrong but the behavior what i am expecting for this standalone example is :
                              When example loads initially the UI should look like attached screen shoot. But when i check the one of the check box above grid (Let's say "Name"), the "Name" as field should get added to my data source and SHOULD BE VISIBLE IN GRID AS LAST COLUMN.

                              Please note that server is adding this column in datasource (i can see that in log) but client is NOT HONORING UPDATED DATASOURCE DEFINATION; it uses previously loaded definition.
                              Attached Files

                              Comment


                                #30
                                Oh, was your expectation that every time the server is contacted for data loading, all DataSource definitions are reloaded? This expectation is not created anywhere in the docs, rather, DataSources are loaded once. You can force a DataSource to reload with the forceReload parameter of DataSource.load(), or you can switch to a different DataSource ID. Both approaches require rebinding any DataBoundComponents.

                                Note that the usage in your sample (generating DataSource fields on the fly for any criteria coming from the client) basically doesn't make sense and opens up a number of security holes. Whatever problem you were trying to solve with that approach, start a new thread for it if you need help, as we've established here that the DynamicDSGenerator API is working as designed and as documented.

                                Comment

                                Working...
                                X