Announcement

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

    Trouble with datasource.addData

    I am attempting to learn how to use the add, remove, update features of datasources. Below is the code I am using and I am getting an error. Can anyone point me in the right direction?

    My DataSource XML:
    Code:
    <DataSource serverType="sql" autoDeriveSchema="true" dbName="CSODatabaseLOCAL"
    ID="UserViews"
    schema="csorepository"
    tableName="user_views">
    	
        <fields>
    	<field name="viewId" nativeName="view_id" type="int" primaryKey="true"/>
           	<field name="userId" nativeName="user_id" type="int"/>
           	<field name="cityId" nativeName="city_id" type="int"/>
           	<field name="viewName" nativeName="view_name" type="text" length="64"/>
           	<field name="viewSensors" nativeName="view_sensors" type="text" length="255"/>
           	<field name="viewStartDate" nativeName="view_start_date" type="datetime"/>
           	<field name="viewEndDate" nativeName="view_end_date" type="datetime"/>
           	<field name="isDefault" nativeName="is_default" type="bool" length="32"/>
        </fields>
    		
        <operationBinding operationType="update" requires="false" />
        
        <operationBinding operationType="add" requires="" />
        
        <operationBinding operationType="remove" operationId="removeUserView" >
        	<whereClause>view_id = $criteria.viewId</whereClause>
        </operationBinding>
    
        <operationBinding operationType="fetch" operationId="fetchUserViews">
        	<whereClause>user_id = $criteria.userId AND city_id = $criteria.cityId</whereClause>
        </operationBinding>
    		
    </DataSource>
    My test code to add the row:
    Code:
    final DataSource userViewDs = DataSource.get("UserViews");
    try {
        Record r = new Record();
        r.setAttribute("userId", 111);
        r.setAttribute("cityId", 222);
        r.setAttribute("viewName", "My first view");
        r.setAttribute("viewSensors", "sens1,sens2");
        r.setAttribute("isDefault", false);
                        
         userViewDs.addData(r);
     } catch (Exception ex) {
        com.google.gwt.user.client.Window.alert(ex.getMessage());
     }
    The exception is not very descriptive.

    "(TypeError) _gwt$exception: <skipped>: Cannot read property 'getOrCreateJsObj' of null"

    I understand it is saying there is a null point somewhere, but I do not see what I have done wrong.

    #2
    Hi wriley,

    my gut feeling says it is related to
    Code:
    <operationBinding operationType="add" requires="" />
    Try to remove the line or at least requires="" and try again (clear cache before just in case).

    Also you should replace com.google.gwt.user.client.Window.alert() with SC.say/warn(), but that is not related to the error.

    Best regards
    Blama

    Comment

    Working...
    X