Announcement

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

    Can't ListGrid.FetchData() again without modification except Criteria DROPONCHANGE

    Can't ListGrid.FetchData() again without modification except Criteria DROPONCHANGE

    I uncessyfull try to fetchData() one more time without modification on the ListGrid.

    The internal cache isn't modified and call fetchData() once again, don't call Fetch to server.

    I try to change the default CriteriaPolicy from DROPONSHORTENING to DROPONCHANGE, but no more effect.

    com.smartgwt.client.types.CriteriaPolicy.DROPONCHANGE
    Cache is dropped whenever criteria changes.
    Code:
    public class ModuleAccueil implements EntryPoint {
    
        ListGridField listGridFieldId = new ListGridField("id","Id");
    		listGridFieldId.setWidth("50px");
    		listGridFieldId.setHidden(true);
    		
    		ListGridField listGridFieldCentral = new ListGridField("zone","Zone");
    		listGridFieldCentral.setWidth("30px");
    		
    		final ListGrid listGrid = new ListGrid();
    		
    		listGrid.setHeaderSpans(
    				new HeaderSpan("MyGrid", new String[]{"id", "zone"}));		
    		listGrid.setHeaderHeight(40);
    		listGrid.setWidth(200);
    		listGrid.setHeight(224);			
    		listGrid.setCanHover(true);
    
    		listGrid.setCanAcceptDrop(true);
    		listGrid.setCanAcceptDroppedRecords(true);
    
    		listGrid.setCanDrag(true);
    		listGrid.setCanDragRecordsOut(true);
    		listGrid.setCanDrop(true);
    		listGrid.setDragType("dndOtStock");
    		listGrid.setDropTypes("dndOtErreur","dndOtAffecte","dndOtStock");
    		
    		listGrid.setDragDataAction(DragDataAction.MOVE);		
    		
    		final RestDataSource dataSource = new RestDataSource();
    		dataSource.setDataFormat(DSDataFormat.XML); 
    		
    		dataSource.setCriteriaPolicy(CriteriaPolicy.DROPONCHANGE);
    //		dataSource.setCriteriaPolicy(CriteriaPolicy.DROPONSHORTENING);
    		
    		Map<String,String> defParams = new HashMap<String, String>();
    		defParams.put("mode", "myMode");
    		
    		dataSource.setDefaultParams(defParams);
            OperationBinding fetch = new OperationBinding();
            fetch.setOperationType(DSOperationType.FETCH);
            fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
              
            dataSource.setOperationBindings(fetch);
    
            dataSource.setFetchDataURL(GWT.getModuleBaseURL()+"datasource");
    		
    		DataSourceIntegerField idDs = new DataSourceIntegerField("id","Id");
    		idDs.setPrimaryKey(true);
    		DataSourceTextField centralDs = new DataSourceTextField("zone","Zone");
    		
    		dataSource.setFields(idDs,centralDs);
    
    		dataSource.setCriteriaPolicy(CriteriaPolicy.DROPONCHANGE);
    		dataSource.setCriteriaPolicy(CriteriaPolicy.DROPONSHORTENING);
    		
    		listGrid.setSortField(1);
    		listGrid.setSortDirection(SortDirection.ASCENDING);
    		
    		listGrid.setDataSource(dataSource);
    		listGrid.setAutoFetchData(true);
    		
    		Button button = new Button("Reload DataSource");
    		button.addClickHandler(new ClickHandler() {
    
    //			@Override
    			public void onClick(ClickEvent event) {
    				System.out.println("onClick");
    				
    				Criteria criteria = new Criteria();
    				criteria.addCriteria("criteriaField", "criteriaValue");
    				listGrid.fetchData(criteria);
    
    								
    			}
    			
    		});
    		
    		
    		VStack vsStack = new VStack();
    		vsStack.setMembers(listGrid,button);
    				
    		RootPanel.get().add(vsStack);
    Servlet :
    Code:
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		System.out.println("doPost");
    		
    		StringBuilder sb = new StringBuilder();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sb.append("<response>");
    sb.append("	<status>0</status>");
    sb.append("	<startRow>0</startRow>");
    sb.append("	<endRow>5</endRow>");
    sb.append("	<totalRows>5</totalRows>");
    sb.append("	<data>");
    sb.append("		<record><empty/><id>999999</id><zone>987</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
    sb.append("		<record><empty/><id>710509</id><zone>KA1</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
    sb.append("		<record><empty/><id>710510</id><zone>KA2</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
    sb.append("		<record><empty/><id>710511</id><zone>KA3</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
    sb.append("		<record><empty/><id>123456</id><zone>012</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
    sb.append("	</data>");
    sb.append("</response>");
    
    	response.getWriter().write(sb.toString()); 
    		
    	}
    I think, the CriteriaPolicy.DROPONCHANGE doesn't work, on y don't know how to use.
    So, why not add a new method or agument to force a new fetch on same DataSource unchanged ?

    #2
    dropOnChange means a change in criteria. The cache will not be dropped if there if setCriteria() is called again but with identical criteria. To force the cache to be dropped, called invalidateCache().

    Comment


      #3
      Immobilia, are you using the SmartClient Server on your app?
      Im asking that, because im trying to make an app like yours (RestDataSource fetching data from a servlet) but when the RestDataSource calls the fetch operation, i got:

      " Uncaught JavaScript exception [uncaught exception: Permission denied to call method XMLHttpRequest.open] in, line 0 "

      Is there a chance for you to post, or send to me your entire app for consulting ?

      Tks for any help

      Comment


        #4
        @mrquejo, your problem is unrelated, you need to use relative URLs for the fetch/add/etc URLs on your RestDataSource. Web pages cannot send requests to servers other than the server they came from, except for special exceptions such as JSONP (see XJSONDataSource).

        Comment


          #5
          Originally posted by Isomorphic
          you need to use relative URLs for the fetch/add/etc URLs on your RestDataSource
          .

          Hi Isomorphic, tks for the tip, i tryed and it worked :D
          Now i got my so dreamed server integration...
          Tks again.

          Comment


            #6
            Code:
            sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sb.append("<response>");
            sb.append("	<status>0</status>");
            sb.append("	<startRow>0</startRow>");
            sb.append("	<endRow>5</endRow>");
            sb.append("	<totalRows>5</totalRows>");
            sb.append("	<data>");
            sb.append("		<record><empty/><id>999999</id><zone>987</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
            sb.append("		<record><empty/><id>710509</id><zone>KA1</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
            sb.append("		<record><empty/><id>710510</id><zone>KA2</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
            sb.append("		<record><empty/><id>710511</id><zone>KA3</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
            sb.append("		<record><empty/><id>123456</id><zone>012</zone><fieldNotDisplay>NotSee</fieldNotDisplay></record>");
            sb.append("	</data>");
            sb.append("</response>");
            is it a mandatory to return the records in above format. I am returning result in some other format like
            <RESULTS>
            <RESULT>
            .. details..
            </RESULT>
            </RESULT>

            I found the above format works fine with smart client but it doesnt with SmartGWT. I am using the XJSONDataSource...

            Comment


              #7
              ajjain,
              Please post your SmartClient sample code that you say works. The same will work in SmartGWT as well. XJSONDataSource requires data to be returned in a specific JSON format. The use in this thread is using RestDataSource which support XML as the dataformat.

              Create a new thread since your post is not directly related to this thread.

              Sanjiv

              Comment


                #8
                mrquejo,
                Please let me know how have you resolved the issue. I have updated a similar issue at the following link:
                http://forums.smartclient.com/showth...urce+fetchData

                Thanks,
                +Abhishek

                Comment


                  #9
                  Originally posted by ajjain
                  mrquejo,
                  Please let me know how have you resolved the issue. I have updated a similar issue at the following link:
                  http://forums.smartclient.com/showth...urce+fetchData

                  Thanks,
                  +Abhishek
                  Hi ajjain.
                  Im at work now, but when i arrive at my home ill post the code.

                  regards

                  Comment

                  Working...
                  X