Announcement

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

    Trouble Saving ListGrid Data locally

    I am trying to save a ListGrid locally (client side) so that I can take that information from the grid and transfer it to a server script via GWT-RPC. However, I am new to SmartGWT, so I'm having difficulty figuring out the DataSource object.

    Right now, I have a ListGrid set up where the majority of the cells are a combobox with three options, "TB" "IR" or "NP". The ListGrid is part of a DynamicForm. When a save Button is clicked, I call grid.saveAllEdits(); and then try to display a value from one of the rows using SC.say(). However, SC.say() always displays the default value, and I get these errors in the console.

    16:31:34.057:TMR8:WARN:Log:findByKeys: dataSource 'isc_OID_28' does not have primary keys declared, can't find record
    16:32:12.869:TMR2:WARN:Log:findByKeys: dataSource 'isc_OID_28' does not have primary keys declared, can't find record
    16:32:12.869:TMR2:WARN:DataSource:isc_OID_28:clientOnly update operation: Unable to find record matching criteria:{monday: "TB"}
    16:32:12.869:TMR2:WARN:DataSource:isc_OID_28:Empty results returned on 'update' on dataSource 'isc_OID_28', unable to update resultSet(s) on DataSource isc_OID_28. Return affected records to ensure cache consistency.

    Here is the entire form. Am I going about this in the right direction or completely wrong with my approach? My ultimate goal is to get the grid cell values stored in a MySQL database, which I will need to access through GWT-RPC. I was just going to go through each record and say getAttributeAsString() and grab all the records, storing them in a POJO WeeklyReport and pass that object to server for processing.

    Code:
    public class WeeklyReportEdit extends ReportEdit {
    	Window popup_window;
    	DynamicForm form;
    	SectionItem tb1_section,tb2_section, tb3_section, ntb_section;
    	DateItem week_of;
    	ComboBoxItem student_name;
    	TextItem tb1, tb2, tb3, ntb;
    	
    	ListGrid tb1_grid,tb2_grid,tb3_grid, ntb_grid;
    	ListGridField loc_col, mon_col,tues_col,wed_col,thurs_col,fri_col;
    	
    	ButtonItem save;
    	ButtonItem cancel;
    	
    	DataSource data_source;
    	
    	public WeeklyReportEdit() {
    		
    		//configure popup window
    		popup_window = new Window();
    		popup_window.setTitle("Weekly Report Form");
    		popup_window.setWidth(625);
    		popup_window.setHeight(500);
    		popup_window.centerInPage();
    		
    		//configure form
    		form = new DynamicForm();
    		form.setWidth(600);
    		form.setPadding(5);
    		form.setNumCols(2);
    		form.setTitleOrientation(TitleOrientation.TOP);
    		
    		//create general fields
    		SectionItem general_section = new SectionItem();
    		general_section.setDefaultValue("General");
    		general_section.setSectionExpanded(true);
    		general_section.setItemIds("student_name","week_of");
    		student_name = new ComboBoxItem("Student Name");
    		student_name.setName("student_name");
    		week_of = new DateItem();
    		week_of.setName("week_of");
    		week_of.setTitle("Week Of");
    		
    		//create behavior text fields
    		SectionItem behavior_section = new SectionItem();
    		behavior_section.setDefaultValue("Monitored Behaviors");
    		behavior_section.setSectionExpanded(true);
    		behavior_section.setItemIds("tb1");
    		tb1 = new TextItem();
    		tb1.setName("tb1");
    		tb1.setTitle("Target Behavior 1");
    		tb1.addChangeHandler(new ChangeHandler() {
    			public void onChange(ChangeEvent e) {
    				tb1_section.setDefaultValue(e.getValue().toString());
    			}
    		});
    		
    		
    		// Create fields for the grids
    		createListGridFields();
    		
    		//create tb1 grid
    		tb1_section = new SectionItem();
    		tb1_section.setDefaultValue("Target Behavior 1");
    		tb1_section.setItemIds("tb1_canvas");
    		tb1_section.setSectionExpanded(false);
    		createTB1Grid();
    		
    		tb1_grid.setFields(loc_col,mon_col,tues_col,wed_col,thurs_col,fri_col);
    		CanvasItem tb1_canvas = new CanvasItem();
    		tb1_canvas.setCanvas(tb1_grid);
    		tb1_canvas.setName("tb1_canvas");
    		tb1_canvas.setShowTitle(false);
    		tb1_canvas.setColSpan(2);
    		
    		//create save and cancel buttons
    		save = new ButtonItem("save");
    		save.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent e) {
    				tb1_grid.saveAllEdits();
    				ListGridRecord record = tb1_grid.getRecord(1);
    				SC.say(record.getAttributeAsString("monday"));
    			}
    		});
    		cancel = new ButtonItem("cancel","Cancel");
    		save.setStartRow(true);
    		save.setEndRow(false);
    		cancel.setStartRow(false);
    		
    		//add all fields to the form
    		form.setFields(new FormItem[] {
    				general_section,
    				student_name,
    				week_of,
    				behavior_section,
    				tb1,
    				tb1_section,
    				tb1_canvas,
    				save,
    				cancel});
    		
    		//add form to popup window
    		popup_window.addItem(form);
    	
    		//display
    		popup_window.show();
    		
    	}
    Note: Helper functions listed in the next posting due to my post being too long.

    #2
    Helper functions for previous post.

    Code:
    private void createListGridFields() {
    		loc_col = new ListGridField("location","Location");
    		loc_col.setCanEdit(false);
    		loc_col.setWidth(125);
    		mon_col = new ListGridField("monday","Monday");
    		mon_col.setWidth(75);
    		tues_col = new ListGridField("tuesday","Tuesday");
    		tues_col.setWidth(75);
    		wed_col = new ListGridField("wednesday","Wednesday");
    		wed_col.setWidth(75);
    		thurs_col = new ListGridField("thursday","Thursday");
    		thurs_col.setWidth(75);
    		fri_col = new ListGridField("friday","Friday");
    		fri_col.setWidth(75);
    	}
    	
    	private void createTB1Grid() {
    		tb1_grid = new ListGrid();
    		tb1_grid.setAutoFitData(Autofit.BOTH);
    		tb1_grid.setAlternateRecordStyles(true);
    		tb1_grid.setCanGroupBy(false);
    		tb1_grid.setCanReorderFields(false);
    		tb1_grid.setCanReorderRecords(false);
    		tb1_grid.setCanSort(false);
    		tb1_grid.setDataSource(getNewDataSource()); 
    		tb1_grid.setAutoFetchData(true);
    		tb1_grid.setCanEdit(true);
    		tb1_grid.setModalEditing(true);
    		tb1_grid.setEditEvent(ListGridEditEvent.CLICK);
    		tb1_grid.setListEndEditAction(RowEndEditAction.DONE);
    		tb1_grid.setAutoSaveEdits(false);
    	}
    	
    	private DataSource getNewDataSource() {
    		DataSource ds = new DataSource();
    		ds.setClientOnly(true);
    		
    		//configure fields
    		DataSourceTextField location_name = new DataSourceTextField("loc_field","Location");
    		ds.addField(location_name);
    		
    		DataSourceTextField mon_field = new DataSourceTextField("monday","Monday");
    		mon_field.setValueMap("TB","IR","NP");
    		//mon_field.setMultiple(true);
    		ds.addField(mon_field);
    		
    		DataSourceTextField tues_field = new DataSourceTextField("tuesday","Tuesday");
    		tues_field.setValueMap("TB","IR","NP");
    		//tues_field.setMultiple(true);
    		ds.addField(tues_field);
    		
    		DataSourceTextField wed_field = new DataSourceTextField("wednesday","Wednesday");
    		wed_field.setValueMap("TB","IR","NP");
    		//wed_field.setMultiple(true);
    		ds.addField(wed_field);
    		
    		DataSourceTextField thurs_field = new DataSourceTextField("thursday","Thursday");
    		thurs_field.setValueMap("TB","IR","NP");
    		//thurs_field.setMultiple(true);
    		ds.addField(thurs_field);
    		
    		DataSourceTextField fri_field = new DataSourceTextField("friday","Friday");
    		fri_field.setValueMap("TB","IR","NP");
    		//fri_field.setMultiple(true);
    		ds.addField(fri_field);
    		
    		//configure records
    		ListGridRecord arrival = new ListGridRecord();
    		arrival.setAttribute("location", "A.M. Bus / Entering");
    		arrival.setAttribute("monday", "NP");
    		arrival.setAttribute("tuesday", "NP");
    		arrival.setAttribute("wednesday", "NP");
    		arrival.setAttribute("thursday","NP");
    		arrival.setAttribute("friday","NP");
    		ds.addData(arrival);
    		
    		ListGridRecord homeroom_1 = new ListGridRecord();
    		homeroom_1.setAttribute("location", "Homeroom 1");
    		homeroom_1.setAttribute("monday", "NP");
    		homeroom_1.setAttribute("tuesday", "NP");
    		homeroom_1.setAttribute("wednesday", "NP");
    		homeroom_1.setAttribute("thursday","NP");
    		homeroom_1.setAttribute("friday","NP");
    		ds.addData(homeroom_1);
    		
    		ListGridRecord reading = new ListGridRecord();
    		reading.setAttribute("location", "Reading");
    		reading.setAttribute("monday", "NP");
    		reading.setAttribute("tuesday", "NP");
    		reading.setAttribute("wednesday", "NP");
    		reading.setAttribute("thursday","NP");
    		reading.setAttribute("friday","NP");
    		ds.addData(reading);
    		
    		ListGridRecord writing = new ListGridRecord();
    		writing.setAttribute("location", "Writing");
    		writing.setAttribute("monday", "NP");
    		writing.setAttribute("tuesday", "NP");
    		writing.setAttribute("wednesday", "NP");
    		writing.setAttribute("thursday","NP");
    		writing.setAttribute("friday","NP");
    		ds.addData(writing);
    		
    		ListGridRecord math = new ListGridRecord();
    		math.setAttribute("location", "Math");
    		math.setAttribute("monday", "NP");
    		math.setAttribute("tuesday", "NP");
    		math.setAttribute("wednesday", "NP");
    		math.setAttribute("thursday","NP");
    		math.setAttribute("friday","NP");
    		ds.addData(math);
    		
    		ListGridRecord lunch = new ListGridRecord();
    		lunch.setAttribute("location", "Lunch");
    		lunch.setAttribute("monday", "NP");
    		lunch.setAttribute("tuesday", "NP");
    		lunch.setAttribute("wednesday", "NP");
    		lunch.setAttribute("thursday","NP");
    		lunch.setAttribute("friday","NP");
    		ds.addData(lunch);
    		
    		ListGridRecord science = new ListGridRecord();
    		science.setAttribute("location", "Science");
    		science.setAttribute("monday", "NP");
    		science.setAttribute("tuesday", "NP");
    		science.setAttribute("wednesday", "NP");
    		science.setAttribute("thursday","NP");
    		science.setAttribute("friday","NP");
    		ds.addData(science);
    		
    		ListGridRecord ss = new ListGridRecord();
    		ss.setAttribute("location", "Social Studies");
    		ss.setAttribute("monday", "NP");
    		ss.setAttribute("tuesday", "NP");
    		ss.setAttribute("wednesday", "NP");
    		ss.setAttribute("thursday","NP");
    		ss.setAttribute("friday","NP");
    		ds.addData(ss);
    		
    		ListGridRecord exploratory = new ListGridRecord();
    		exploratory.setAttribute("location", "Exploratory");
    		exploratory.setAttribute("monday", "NP");
    		exploratory.setAttribute("tuesday", "NP");
    		exploratory.setAttribute("wednesday", "NP");
    		exploratory.setAttribute("thursday","NP");
    		exploratory.setAttribute("friday","NP");
    		ds.addData(exploratory);
    		
    		ListGridRecord homeroom_2 = new ListGridRecord();
    		homeroom_2.setAttribute("location", "Homeroom 2");
    		homeroom_2.setAttribute("monday", "NP");
    		homeroom_2.setAttribute("tuesday", "NP");
    		homeroom_2.setAttribute("wednesday", "NP");
    		homeroom_2.setAttribute("thursday","NP");
    		homeroom_2.setAttribute("friday","NP");
    		ds.addData(homeroom_2);
    		
    		ListGridRecord departure = new ListGridRecord();
    		departure.setAttribute("location", "P.M. Bus / Departure");
    		departure.setAttribute("monday", "NP");
    		departure.setAttribute("tuesday", "NP");
    		departure.setAttribute("wednesday", "NP");
    		departure.setAttribute("thursday","NP");
    		departure.setAttribute("friday","NP");
    		ds.addData(departure);
    		
    		return ds;
    	}

    Comment


      #3
      Problem fixed. It seems that the lack of setting a primary key caused the issue. I originally thought the primary key would work similar to one for a database making the process faster but wouldn't cause issues if it wasn't set, but in this case it seems that without the primary key it was unable to find a matching record. In my case, setting a primary key for location field fixed it.

      Comment


        #4
        Cool. There was an indicator in the logs for this :


        16:31:34.057:TMR8:WARN:Log:findByKeys: dataSource 'isc_OID_28' does not have primary keys declared, can't find record

        Comment


          #5
          Just a quick note that a primary key in a database makes things faster but it *also serves as the records idenity* (a unique way of referring to it) and this is the reason that SmartGWT needs you to declare a primaryKey.

          Comment


            #6
            How to declare a DataSource primary key? I'm using OnlyClient = true.

            Best Regards!

            Comment

            Working...
            X