Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17th Feb 2010, 18:49
AlexMaddern AlexMaddern is offline
Registered Developer
 
Join Date: Nov 2009
Posts: 26
Default ValuesManager.getValuesAsCriteria() missing?

I'm trying to span a search form over two cells in an HLayout. Four fields on one side and four on the other. I'm using ValuesManager as in the example in the Showcase, but when I attempt to recreate the call from the button to filter a datasourceI have notices that the getValuesAsCriteria is not part of Values Manager ? I assumed that it would take the place of the DynamicForm in this splitting instance ?

Old code with a single Form:
Code:
searchButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        if (myForm.validate()) {
            myListGrid.filterData(myForm.getValuesAsCriteria());
        }
    }
});
Trying to do the same with two forms linked through a ValuesManager:
Code:
searchButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        if (valuesManager.validate()) {
            myListGrid.filterData(valuesManager.getValuesAsCriteria()); // err?
        }
    }
});
Any guidance on this would be gratefully received.

Al
Reply With Quote
  #2  
Old 18th Feb 2010, 06:42
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,580
Default

We'll that add API, in the meantime, manually converting to Criteria is required.
Reply With Quote
  #3  
Old 18th Feb 2010, 13:55
AlexMaddern AlexMaddern is offline
Registered Developer
 
Join Date: Nov 2009
Posts: 26
Default

Understood. Will do.

There appears to be one further issue with the ValueManager which you may want to look into.

If I have a / character in the name of a form item it breaks the Values Map in the ValueManager, as follows

Note: the DynamicForm works perfectly with / in the field name, this is only an issue in the ValueManager.

Code:
TextItem campusTextItem = new TextItem();  
campusTextItem.setName("institute/campus");
...

searchButtonItem.addClickHandler(new ClickHandler() {  
	public void onClick(ClickEvent event) {
		if (vm.validate()) {
			Criteria criteria = new Criteria();
			Map formValues = vm.getValues();
	 		Iterator it = formValues.entrySet().iterator();
	 		while (it.hasNext()) {
	 	        Map.Entry pairs = (Map.Entry)it.next();
 	 		GWT.log("VM Keys: " + pairs.getKey() + " = " + pairs.getValue());
	 	        criteria.addCriteria((String)pairs.getKey() ,(String)pairs.getValue());
	 	    }
			myListGrid.filterData(criteria);
		}
	}  
});
I get the following from the Log
Code:
VM Keys: institute = [object Object]
If I replace the / with an _ as follows it works fine
Code:
TextItem campusTextItem = new TextItem();  
campusTextItem.setName("institute_campus");
...

searchButtonItem.addClickHandler(new ClickHandler() {  
	public void onClick(ClickEvent event) {
		if (vm.validate()) {
			Criteria criteria = new Criteria();
			Map formValues = vm.getValues();
	 		Iterator it = formValues.entrySet().iterator();
	 		while (it.hasNext()) {
	 	        Map.Entry pairs = (Map.Entry)it.next();
	 	        criteria.addCriteria(pairs.getKey().toString().replace('_','/') ,(String)pairs.getValue());
	 	 	GWT.log("VM Keys: " + pairs.getKey() + " = " + pairs.getValue());
	 	    }
			myListGrid.filterData(criteria);
		}
	}  
});
I get
Code:
VM Keys: institute_campus = abc123
Could this be fixed at the same time ?
Reply With Quote
  #4  
Old 18th Feb 2010, 13:57
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,580
Default

FormItem.name in general must be an identifier, by luck you have not yet hit the many things your "/" would break. This will be not be changed.
Reply With Quote
  #5  
Old 18th Feb 2010, 14:24
AlexMaddern AlexMaddern is offline
Registered Developer
 
Join Date: Nov 2009
Posts: 26
Default

Quote:
Originally Posted by Isomorphic
FormItem.name in general must be an identifier, by luck you have not yet hit the many things your "/" would break. This will be not be changed.
OK, but it breaks the behaviour in the DynamicForm which I thought ValueManager is supposed to mirror. DynamicForm allows the use of / in the name.

For convenience I am using the xpath path to the source element in the name and this is working well in our use case. I can work around this limitation in ValueManager as shown in the sample, but I see no reason to have DynamicForm and ValueManager behave differently? Can't we simply have ValueManager mirror DynamicForm as the documentation suggests and "developer beware" if the client chooses to go down this route ?

Out of interest what other aspects of SmartClient would the "/" break ? Your comment sounds quite ominous but provides no explanation.
Reply With Quote
  #6  
Old 18th Feb 2010, 14:40
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,580
Default

Again, it is considered a usage error in both DynamicForm and ValuesManager. The fact that you haven't hit any of the problems it causes does not mean it's supported - it isn't.
Reply With Quote
  #7  
Old 18th Feb 2010, 14:48
AlexMaddern AlexMaddern is offline
Registered Developer
 
Join Date: Nov 2009
Posts: 26
Default

Quote:
Originally Posted by Isomorphic
Again, it is considered a usage error in both DynamicForm and ValuesManager. The fact that you haven't hit any of the problems it causes does not mean it's supported - it isn't.
Sure, you have said that but can you explain why? What is it about the / that makes it some problematic?
Reply With Quote
  #8  
Old 19th Feb 2010, 06:05
timprice17 timprice17 is offline
Registered Developer
 
Join Date: Jun 2009
Posts: 8
Default

Maybe because "/" is a special character in XPath is the reason.
Reply With Quote
  #9  
Old 19th Feb 2010, 12:36
AlexMaddern AlexMaddern is offline
Registered Developer
 
Join Date: Nov 2009
Posts: 26
Default

Quote:
Originally Posted by timprice17
Maybe because "/" is a special character in XPath is the reason.
Agreed, that's the very reason I'm using it. Works brilliantly in my use case. Perhaps not if your using the inbuilt datasources for REST
Reply With Quote
  #10  
Old 2nd Dec 2012, 06:47
vostapenko vostapenko is offline
Registered Developer
 
Join Date: Aug 2012
Posts: 125
Default

Quote:
Originally Posted by Isomorphic View Post
We'll that add API, in the meantime, manually converting to Criteria is required.
Any success on this one? Or anything like Evaluator.parseAdvancedCriteria(map)?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


© 2010,2011 Isomorphic Software. All Rights Reserved