Hi Isomorphic,
could you advise how to implement the following:
- DataBound Country-Dropdown, valueField=country_id (easy, prerequisite)
- DataBound Zipcode-Dropdown, where the selected item of the Country-Dropdown should be an additional criteria to the entered text in the Zipcode-Dropdown.
I did the following, as this was the only way I could inject the criteria:
When you look at the server-log now, there are always 3(!) criteria:
1x ZIPCODE.startsWith, ZIPCODE.iContains, COUNTRY_ID.equals. I would't care for the iContains, which is added automatically, even though I set "setTextMatchStyle(TextMatchStyle.STARTS_WITH);" (see class code below), but what also happens is that the suggestion box doesn't show values it should show.
Example: I enter "12", suggestion-list is 12043, 12045, 12047, 12049, 12051, 12053, 12055, 12057, 12059, 12099, 12101, 12103, 12105, ....
when I enter an additional "0" afterwards, the list gets empty, even though there should be data shown. An additional DB-fetch is not issued. I tried around with invalidateCache (see code above), but it didn't work out, either (still no fetch!).
It gets even worse with setAddUnknownValues(false), because then the ChangedHandler isn't called anymore (which is correct according to the docs http://www.smartclient.com/smartgwte...wnValues%28%29, but then my check for the selected country isn't possible at all.
Could you advise
a. How to solve the use-case best (for both setAddUnknownValues(false/true)),
b. If the current behaviour with the emptying suggestionbox and the iContains-criteria is an error.
Thanks in advance,
Blama
Code for ComboBoxItemZipcode.java
could you advise how to implement the following:
- DataBound Country-Dropdown, valueField=country_id (easy, prerequisite)
- DataBound Zipcode-Dropdown, where the selected item of the Country-Dropdown should be an additional criteria to the entered text in the Zipcode-Dropdown.
I did the following, as this was the only way I could inject the criteria:
Code:
final ComboBoxItemZipcode zipcodeCBIZ = new ComboBoxItemZipcode("ZIPCODE"); zipcodeCBIZ.setAddUnknownValues(true); zipcodeCBIZ.addChangedHandler(new ChangedHandler() { @Override public void onChanged(ChangedEvent event) { Criterion currentCountryCriteria = new Criterion("COUNTRY_ID", OperatorId.EQUALS, countryCBIC.getValueAsString()); Criterion currentZipcodeCriteria = new Criterion("ZIPCODE", OperatorId.STARTS_WITH, zipcodeCBIZ.getValueAsString()); AdvancedCriteria ac = new AdvancedCriteria(); ac.buildCriterionFromList(OperatorId.AND, new Criterion[] { currentCountryCriteria, currentZipcodeCriteria }); zipcodeCBIZ.setOptionCriteria(ac); // zipcodeCBIZ.getOptionDataSource().invalidateCache(); // zipcodeCBIZ.invalidateDisplayValueCache(); } });
Code:
=== 2013-01-09 12:17:30,678 [c-10] INFO SQLDataSource - [builtinApplication.fetchSuggestionList] Performing fetch operation with criteria: {criteria:[{fieldName:"COUNTRY_ID",operator:"equals",value:"246"},{fieldName:"ZIPCODE",operator:"startsWith",value:"123"},{fieldName:"ZIPCODE",operator:"iContains",value:"123"}],operator:"and",_constructor:"AdvancedCriteria"} values: {criteria:[{fieldName:"COUNTRY_ID",operator:"equals",value:"246"},{fieldName:"ZIPCODE",operator:"startsWith",value:"123"},{fieldName:"ZIPCODE",operator:"iContains",value:"123"}],operator:"and",_constructor:"AdvancedCriteria"}
Example: I enter "12", suggestion-list is 12043, 12045, 12047, 12049, 12051, 12053, 12055, 12057, 12059, 12099, 12101, 12103, 12105, ....
when I enter an additional "0" afterwards, the list gets empty, even though there should be data shown. An additional DB-fetch is not issued. I tried around with invalidateCache (see code above), but it didn't work out, either (still no fetch!).
It gets even worse with setAddUnknownValues(false), because then the ChangedHandler isn't called anymore (which is correct according to the docs http://www.smartclient.com/smartgwte...wnValues%28%29, but then my check for the selected country isn't possible at all.
Could you advise
a. How to solve the use-case best (for both setAddUnknownValues(false/true)),
b. If the current behaviour with the emptying suggestionbox and the iContains-criteria is an error.
Thanks in advance,
Blama
Code for ComboBoxItemZipcode.java
Code:
public final class ComboBoxItemZipcode extends ComboBoxItem { final private DataSource zipcodeDS = DataSource.get(DatasourceEnum.V_ZIPCODE.getValue()); public ComboBoxItemZipcode(String name) { super(name); setOptionDataSource(zipcodeDS); setOptionOperationId("fetchSuggestionList"); setCachePickListResults(false); setValueField("ZIPCODE"); setSortField("ZIPCODE"); setTextMatchStyle(TextMatchStyle.STARTS_WITH); //setEmptyPickListHeight(0); setShowPickerIcon(false); setAddUnknownValues(true); setDefaultToFirstOption(false); setBrowserSpellCheck(false); ListGridField zipcode = new ListGridField("ZIPCODE"); ListGridField citysuggestion = new ListGridField("CITYSUGGESTION"); setPickListFields(zipcode, citysuggestion); setPickListHeaderHeight(0); setPickListWidth(200); setPickListHeight(200); } }
Comment