Announcement

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

    fields cannot be added to a dataSource after the underlying component has been create

    working on smartEE eval + eclipse + google app engine

    1. The line with the error is
    countryDS.addField( field );
    I didn't start to use DataSource (got the error before DataSource is added to VStack ???)

    code bellow is updated from gae-CloudSQL which I managed to make it work at - http://adaptcloud.appspot.com/

    final VStack vStack = new VStack();
    final DataSource countryDS = DataSource.get( master_data_source);//"country_DataSource"
    final DataSource cityDS = DataSource.get( details_data_source);//"city_DataSource"
    if( countryDS != null){
    //DataSourceField(String name, FieldType type, String title, int length, boolean required)
    DataSourceField field = new DataSourceField( "counties", FieldType.TEXT, "Counties", 30, true);
    countryDS.addField( field );
    String[] fields = countryDS.getFieldNames();
    Window.alert( "Country fields = " + fields);
    }

    2. P.S. now I am tring hard to make it dynamic with "extends DataSourceLoader" and load with DataSource.fromXML but the order of operations kills me - I am always too late and the system rejects me - so I switch to 1.
    The only time when fromXML() is early and accepted is the call from inside initial html of app engine = GAECloud.html

    3. I will probably switch to open source to understand the process and than come back to smartEE eval

    #2
    Optimize Client Code for Dynamic Data Sources

    I succeed on path 2 and abandoned path 1 and 3 (probably the error on 1 is because I call it from client and the server mirror data source structures are ready to go and frozen)

    New question

    short question
    how do you call from the server the following client call ?
    how do you generate the JSON ?
    isc.DataSource.create( some JSON stuff with my fields created at 1))

    detaild question

    now the dynamic data source is working but help me to optimize the workaround code mess bellow
    help me execute from server tasks 2,3,4,5 described bellow
    I am on the client
    1. I send some of my tasks to the server (I want to execute also 5 from here, from the server(and avoid 2,3,4)
    ON the server I prepare MyDataSource fields for your loader
    2. I call "/GAECloud_js/sc/DataSourceLoader?dataSource=mydynamicdatasource
    3. I wait to receive back a javascript
    4. I insert eval(javascript) in gwt
    (something like isc.DataSource.create( some JSON stuff with my fields created at 1))
    5. the executed script goes on server to register datasource
    6. ??? I should wait here for the completion
    7. I create the client form with the new dynamic data source

    8. some sort of Evrika ! (but complex patterns like this go bad in multitasking real life)

    Thank you

    Dorin

    Comment


      #3
      I found some answer at the first question

      https://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/docs/DataSourceDeclaration.html

      Creating DataSources

      DataSources can be specified in XML format, in which case the Smart GWT server is used to load the DataSource, or DataSources can be programmatically created on the client.
      Whether a DataSource is loaded via the Smart GWT server or programmatically created client-side, identical requests will ultimately be submitted to the server. However, DataSources defined in XML are loaded and used by the Smart GWT Server, enabling many features including synchronized client-server validation, request bundling, file upload, and optional automatic SQL/JPA/Hibernate connectivity (see the Server Summary for details).

      DataSources can be programmatically created on the client like so:

      DataSource ds = new DataSource();
      ds.setID("supplyItem");
      DataSourceTextField nameField = new DataSourceTextField("itemName", "Name");
      // create other fields
      ds.setFields(nameField, ...);

      ...

      So the secret is to start with an empty DataSource (new DataSource()) - if it is initaialized via "/GAECloud_js/sc/DataSourceLoader?dataSource=...." than is frozen

      Comment


        #4
        Done

        countryDS = new DataSource();
        .............
        countryDS.setFields( fields_list);

        works perfect from client to generate whatever you want

        abandoned "XML generation" + "my loader" and this line from main html
        <script type="text/javascript" language="javascript"
        src="GAECloud_js/sc/DataSourceLoader?dataSource=city_DataSource,...">
        </script>

        (I also cut this <script type="text/javascript" language="javascript" src="GAECloud_js/GAECloud_js.nocache.js ....)

        Comment


          #5
          You're probably going in the wrong direction - DataSources created client-side with "new DataSource()" cannot use any settings that control server-side behavior.

          You've also given no indication of why you're trying to dynamically generate DataSources - this may be another misunderstanding on your part, and be unnecessary for your app.

          Comment

          Working...
          X