Announcement

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

    GridList data update

    Hi everybody,

    I'm just searching how to update the data in a gridlist. Here is my problem : I create an empty GridList, then, with an Ajax call I catch a new set of value from the database. I convert them into an ArrayList<MyResult> and then in a MyResult[], and then i use the setData(MyResult[]) function.
    But noting change in my GridList. I set the autoFetchData value to true but it doesn't change anything.

    Does any of you have an idea?

    Thanks a lot,

    romain.

    #2
    Read up on DataSources. You should be able to create one that talks to your Ajax fetch method.

    Comment


      #3
      Thanks for the hint.

      I tried Datasource, but I get a javascript message saying this " isc_DataSource_0: attempt to use DataSource of type iscServer without SmartClient Server option.[...]"

      Ok, I found it, I just had to set dataSource.setClientOnly(true); and it's working now :)
      Last edited by romain.vdk; 15 Jun 2010, 23:03.

      Comment


        #4
        Ok, now i'm blocked by the DataSource content.
        I can simply add some data to it with the datasource.add() function.
        But when I make a new call, old data are not destroyed, how can I do that? I don't find any way of doing a removeAll() ...
        Thanks

        Comment


          #5
          setTestData(null) or setTestData(new RecordList());

          Comment


            #6
            thanks for the reply

            my bad, I didn't saw it ... I test that just now
            Last edited by romain.vdk; 16 Jun 2010, 05:09.

            Comment


              #7
              ok, I tested that, but it does not change anything ...
              When I submit my call, data is just added after the previous results, without making the grid empty ...

              Comment


                #8
                Can you post you code so we can see what you are actually trying to accomplish? It's really hard to tell how you are putting this together to answer your questions properly.

                Comment


                  #9
                  What i wanna do is very simple. I modified the default GWT application to show a ListGrid. When the user enters a text and click on send button, a call to the server is made and returns some data. Next, the data is displayed in the ListGrid.
                  Now, when I make a second call, the new data is not alone in the ListGrid : old data is still there ... What I wanna do is simply remove the old data when the async server call is a success et replace it by the new data ...

                  Here it is the code :
                  Code:
                  package be.uniway.cesar.client;
                  
                  import java.util.List;
                  
                  import be.uniway.cesar.client.data.TransportResultRecord;
                  import be.uniway.cesar.server.entities.TransportResult;
                  
                  import com.google.gwt.core.client.EntryPoint;
                  import com.google.gwt.core.client.GWT;
                  import com.google.gwt.event.dom.client.ClickEvent;
                  import com.google.gwt.event.dom.client.ClickHandler;
                  import com.google.gwt.event.dom.client.KeyCodes;
                  import com.google.gwt.event.dom.client.KeyUpEvent;
                  import com.google.gwt.event.dom.client.KeyUpHandler;
                  import com.google.gwt.user.client.rpc.AsyncCallback;
                  import com.google.gwt.user.client.ui.Button;
                  import com.google.gwt.user.client.ui.DialogBox;
                  import com.google.gwt.user.client.ui.HTML;
                  import com.google.gwt.user.client.ui.Label;
                  import com.google.gwt.user.client.ui.RootPanel;
                  import com.google.gwt.user.client.ui.TextBox;
                  import com.google.gwt.user.client.ui.VerticalPanel;
                  import com.smartgwt.client.core.DataClass;
                  import com.smartgwt.client.data.DataSource;
                  import com.smartgwt.client.widgets.grid.ListGrid;
                  import com.smartgwt.client.widgets.grid.ListGridField;
                  
                  /**
                   * Entry point classes define <code>onModuleLoad()</code>.
                   */
                  public class MavenAppRpc implements EntryPoint {
                  	/**
                  	 * The message displayed to the user when the server cannot be reached or
                  	 * returns an error.
                  	 */
                  	private static final String SERVER_ERROR = "An error occurred while "
                  			+ "attempting to contact the server. Please check your network "
                  			+ "connection and try again.";
                  
                  	/**
                  	 * Create a remote service proxy to talk to the server-side Greeting service.
                  	 */
                  	private final GreetingServiceAsync greetingService = GWT
                  			.create(GreetingService.class);
                  	
                  	/**
                  	 * This is the entry point method.
                  	 */
                  	public void onModuleLoad() {
                  		final Button sendButton = new Button("Send");
                  		final TextBox nameField = new TextBox();
                  		final ListGrid listGrid = new ListGrid();
                  		final DataSource dataSource = new DataSource();
                  		
                  		nameField.setText("GWT User");
                  		sendButton.addStyleName("sendButton");
                  		RootPanel.get("nameFieldContainer").add(nameField);
                  		RootPanel.get("sendButtonContainer").add(sendButton);
                  		
                  		ListGridField ituCode = new ListGridField("itucode","Itu Code");
                  		ListGridField lastStatus = new ListGridField("lastStatus","Last Status");
                  		ListGridField terminals = new ListGridField("terminals","Departure Terminal<br/>Destination Terminal<br/>Final Terminal");
                  		ListGridField fullOrEmpty = new ListGridField("fullOrEmpty","Full/Empty");
                  		ListGridField weights = new ListGridField("weights","Net Weight (kg)<br/>Gross Weight(kg)");
                  		ListGridField statusDate = new ListGridField("statusDate","Status Date");
                  		ListGridField departureDate = new ListGridField("departureDate","Departure Date");
                  		ListGridField actors = new ListGridField("actors","Invoicing<br/>Sender<br/>Receiver");
                  		ListGridField refNumbers = new ListGridField("refNumbers","Customer Ref<br/>Operator Ref");
                  		ListGridField controlNumbers = new ListGridField("controlNumbers","Ctrl train Number<br/>Railway train number<br/>Wagon number");
                  		
                  		listGrid.setFields(ituCode,lastStatus,terminals,fullOrEmpty,weights,statusDate,departureDate,actors,refNumbers,controlNumbers);
                  		listGrid.setWidth100();
                  		listGrid.setHeight("300px");
                  		listGrid.setHeaderHeight(50);
                  		listGrid.setCellHeight(50);
                  		listGrid.setAutoFetchData(true);
                  		dataSource.setClientOnly(true);
                  		listGrid.setDataSource(dataSource);
                  		listGrid.setShowFilterEditor(true);
                  		listGrid.setFilterOnKeypress(true);
                  		RootPanel.get("gridPanel").add(listGrid);
                  
                  
                  		// Focus the cursor on the name field when the app loads
                  		nameField.setFocus(true);
                  		nameField.selectAll();
                  
                  		// Create the popup dialog box
                  		final DialogBox dialogBox = new DialogBox();
                  		dialogBox.setText("Remote Procedure Call");
                  		dialogBox.setAnimationEnabled(true);
                  		final Button closeButton = new Button("Close");
                  		// We can set the id of a widget by accessing its Element
                  		closeButton.getElement().setId("closeButton");
                  		final Label textToServerLabel = new Label();
                  		final HTML serverResponseLabel = new HTML();
                  		VerticalPanel dialogVPanel = new VerticalPanel();
                  		dialogVPanel.addStyleName("dialogVPanel");
                  		dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
                  		dialogVPanel.add(textToServerLabel);
                  		dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
                  		dialogVPanel.add(serverResponseLabel);
                  		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
                  		dialogVPanel.add(closeButton);
                  		dialogBox.setWidget(dialogVPanel);
                  
                  		// Add a handler to close the DialogBox
                  		closeButton.addClickHandler(new ClickHandler() {
                  			public void onClick(ClickEvent event) {
                  				dialogBox.hide();
                  				sendButton.setEnabled(true);
                  				sendButton.setFocus(true);
                  			}
                  		});
                  
                  		// Create a handler for the sendButton and nameField
                  		class MyHandler implements ClickHandler, KeyUpHandler {
                  			public void onClick(ClickEvent event) {
                  				requestItu();
                  			}
                  			public void onKeyUp(KeyUpEvent event) {
                  				if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                  					requestItu();
                  				}
                  			}
                  			private void requestItu() {
                  				sendButton.setEnabled(false);
                  				String initItu = nameField.getText();
                  				initItu = "%" + initItu + "%";
                  				TransportResult tr = new TransportResult();
                  				tr.setItuCode(initItu);
                  				greetingService.getTransportWithCriteria(tr, new AsyncCallback<List<TransportResult>>() {
                  					public void onFailure(Throwable arg0) {
                  						dialogBox.setText("Remote Procedure Call - Failure");
                  						serverResponseLabel
                  								.addStyleName("serverResponseLabelError");
                  						serverResponseLabel.setHTML(SERVER_ERROR);
                  						dialogBox.center();
                  						closeButton.setFocus(true);
                  					}
                  					public void onSuccess(List<TransportResult> arg0) {
                  						sendButton.setEnabled(true);
                  						dataSource.setTestData(new DataClass[0]);
                  						for ( TransportResult tr : arg0 ) {
                  							dataSource.addData(new TransportResultRecord(tr));
                  						}
                  					}
                  				});
                  			}
                  		}
                  
                  		// Add a handler to send the name to the server
                  		MyHandler handler = new MyHandler();
                  		sendButton.addClickHandler(handler);
                  		nameField.addKeyUpHandler(handler);
                  	}
                  }
                  Last edited by romain.vdk; 16 Jun 2010, 05:47.

                  Comment


                    #10
                    no idea about that ? I also tried to set the cache time to 0 but it doesn't change anything too ...

                    I just tried to create an ArrayList containing the data and executing the remove method of the datasource, but that is not working too ...
                    Last edited by romain.vdk; 17 Jun 2010, 05:14.

                    Comment


                      #11
                      Try dropping the addData calls and just build a TransportResultRecord[] then call setTestData with it. Too bad you can't just build a Datasource for your service and then all this sync work would be handled for you...

                      Comment


                        #12
                        I alreday tried that and it doesn't work :s

                        Building a datasource for my service? How do I do that?? I never saw that anywhere ...

                        Comment


                          #13
                          Try the SC or SGWT docs to get full details on what a datasource gives you via databinding. Start here.

                          If you can provide an implementation of a datasource that implements your fetch, you can just call fetchData() on the grid to get updated information and drop your custom calls and response handling.

                          On another note, I just realized your datasource does not define any fields. You should define the fields on the datasource and let the grid pick them up from there unless you have to reorder them. See the samples for details on defining datasources and how the fields are merged into the grid.

                          Comment


                            #14
                            Thanks for that.
                            When I read those pages, it seems I had another point of view of the datasource.


                            can you confirm if my attached schema is correct ?
                            Attached Files

                            Comment


                              #15
                              A datasource can work either way you describe. It is most common to do the second.

                              Comment

                              Working...
                              X