Announcement

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

    advanced criteria with floats gives an error

    I'm trying to form a post with this format:
    Code:
    data :{
      criteria: [
         {fieldname..
           operator...
           value: [2.34355345, 33.23423423...]
      ]
    }
    There are two parts that I'm focusing on, the "criteria" attribute and the value array. The values are coming to be me as doubles. I've tried creating criteria something like this:
    Code:
    mapCriteria.addCriteria("map_bounds", new Double[]{3.324655, 3.34342423});
    criteria.buildCriterionFromList(OperatorId.AND, new Criterion[]{mapCriteria.asAdvancedCriteria(), grid.getCriteria().asAdvancedCriteria()});
    (the grid section isn't relevent for this discussion)
    Unfortunately the asAdvancedCriteria turns it into a big OR, which isn't what I'm looking for, I want to actually end up with an array.

    So I've tried turning the incoming data into an array of floats so I can use advanced criteria:
    Code:
    AdvancedCriteria mapCriteria = new AdvancedCriteria("map_bounds", OperatorId.EQUALS, new Float[]{2f,3f,2f,1f});
    On fetch data this fails:
    Code:
    Caused by: com.google.gwt.core.client.JavaScriptException: (null): null
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
        at com.smartgwt.client.widgets.grid.ListGrid.fetchData(ListGrid.java)
    Though if I replace the array with an array of integers it doesn't fail.

    I have one question with a few parts:
    The central question is: is there a way to achieve the intended format given above with doubles as the input?
    I'm fine converting to floats. Related: Is there a bug with arrays of floats that is stopping advanced criteria from working, if so is there a workaround.

    #2
    Only certain operators (like IN_SET) actually allow arrays. Otherwise, arrays are a shorthand for OR. So no, you can't pass an array to arbitrary operators, because that's basically invalid criteria.

    Can you add code to a sample and get the issue with floats? If so, just mention which sample and the code you need to add. But be sure to test with the latest build.

    Comment


      #3
      Here's a simple example. The first uses floats and fails in the client(Firefox, dev mode). The second uses Integers and doesn't. I tried it against the latest version and it does it there too.

      Fails:
      Code:
      public class Main implements EntryPoint {	
      	@Override
      	public void onModuleLoad() {	
      		HLayout hlay = new HLayout(4);	
      		ListGrid grid = new ListGrid(){{
      			setDataSource(new DataSource("app/items","app/item"));
      		}};
      		hlay.addMember(grid);	
      		hlay.show();
      		
      		grid.fetchData(new AdvancedCriteria("arrayOfFloats", OperatorId.IN_SET, new Float[]{1.2f, 4.3f}));
      	}
      }
      Doesn't fail in the client:
      Code:
      public class Main implements EntryPoint {	
      	@Override
      	public void onModuleLoad() {	
      		HLayout hlay = new HLayout(4);
      		ListGrid grid = new ListGrid(){{
      			setDataSource(new DataSource("app/items","app/item"));
      		}};
      		hlay.addMember(grid);	
      		hlay.show();		
      	
              	grid.fetchData(new AdvancedCriteria("arrayOfIntegers", OperatorId.IN_SET, new Integer[]{1, 4}));
      	}
      }
      Last edited by pghosh; 15 Jan 2013, 13:17.

      Comment


        #4
        This issue with handling of arrays of floats should be fixed for 3.1 and 4.0 (as of tomorrow's build).

        Comment

        Working...
        X