Isomorphic,
There was a requirement where there would be two drop downs(one with list of years, and one with list of months). The values would be populated from the database.
Here is the UI code
This is my ds.xml file
Here is the DMI class
By default, fromYear SelectItem would result into population of Years, But fromMonth would be populated based on what would be selected when the data gets loaded in fromYear Select Item.
Here are my logs
Please let me know what is the issue here and is this is the better approach to achieve Field dependency?
There was a requirement where there would be two drop downs(one with list of years, and one with list of months). The values would be populated from the database.
Here is the UI code
Code:
fromYear.setOptionDataSource(DataSource.get("dateRange")); Criteria criteria = new Criteria(); criteria.addCriteria("PRODUCT_ID","NA_ADB"); criteria.addCriteria("CLIENT_ID", 99); fromYear.setOptionCriteria(criteria); fromYear.setOptionOperationId("yearFetch"); fromYear.setValueField("YEAR_NUM"); fromYear.setAutoFetchData(true); fromYear.setName("fromYear"); fromYear.setTitle("From"); fromYear.setDefaultToFirstOption(true); fromYear.setWidth(60); fromYear.setWrapTitle(true); fromYear.setColSpan(1); //fromYear.setValueMap(); fromMonth.setOptionDataSource(DataSource.get("dateRange")); Criteria criteriaFromMonth = new Criteria(); criteriaFromMonth.addCriteria("PRODUCT_ID","NA_ADB"); criteriaFromMonth.addCriteria("CLIENT_ID", 99); int selectedFromYear = 2011; // (Integer)fromYear.getValue(); criteriaFromMonth.addCriteria("YEAR_NUM" ,selectedFromYear); fromMonth.setOptionCriteria(criteriaFromMonth); fromMonth.setOptionOperationId("monthFetch"); fromMonth.setValueField("MONTH_SHORT_NUM"); fromMonth.setAutoFetchData(true); fromMonth.setName("fromMonth"); fromMonth.setShowTitle(false); fromMonth.setType("comboBox"); fromMonth.setWidth(60); fromMonth.setDefaultToFirstOption(true); fromMonth.setWrapTitle(false); fromMonth.setColSpan(1); fromMonth.setAutoFetchData(true); // fromMonth.setValueMap("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","NOV","DEC"); fromYear.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent changedEvent) { int selectedItem = (Integer) changedEvent.getValue(); fromMonth.clearValue(); fromMonth.setOptionDataSource(DataSource.get("dateRange")); Criteria criteriaFromMonth = new Criteria(); criteriaFromMonth.addCriteria("PRODUCT_ID","NA_ADB"); criteriaFromMonth.addCriteria("CLIENT_ID", 99); // int selectedFromYear = 2011; // (Integer)fromYear.getValue(); criteriaFromMonth.addCriteria("YEAR_NUM" ,selectedItem); fromMonth.setOptionCriteria(criteriaFromMonth); fromMonth.setOptionOperationId("monthFetch"); fromMonth.setValueField("MONTH_SHORT_NUM"); fromMonth.setAutoFetchData(true); fromMonth.redraw(); } });
Code:
<DataSource ID="dateRange" table="CLIENT_VALID_DATES" serverType="sql" dbName="Oracle" showPrompt="false" qualifyColumnNames="false"> <fields> <field name="CLIENT_ID" type="number" required="false" title="CLIENT_ID"/> <field name="YEAR_NUM" type="number" required="true" title="YEAR_NUM"/> <field name="MONTH_NUM" type="number" required="false" title="MONTH_NUM"/> <field name="MONTH_SHORT_NAME" type="text" required="false" title="MONTH_SHORT_NAME"/> <field name="MONTH_ID" type="number" required="false" title="MONTH_ID"/> <field name="QUARTER_ID" type="number" required="false" title="QUARTER_ID"/> <field name="PRODUCT_ID" type="text" required="false" title="PRODUCT_ID"/> </fields> <operationBindings> <operationBinding operationId="yearFetch" operationType="fetch"> <serverObject lookupStyle="new" className="com.sabre.apd.mi.smartgwt.server.DateRangeDMI"/> <selectClause> DISTINCT month_num, month_short_name, year_num </selectClause> <tableClause> CLIENT_VALID_DATES </tableClause> <whereClause> ($defaultWhereClause) </whereClause> <orderClause> year_num desc ,month_num desc </orderClause> </operationBinding> </operationBindings> <operationBindings> <operationBinding operationId="monthFetch" operationType="fetch"> <serverObject lookupStyle="new" className="com.sabre.apd.mi.smartgwt.server.DateRangeDMI"/> </operationBinding> </operationBindings> </DataSource>
Code:
public class DateRangeDMI { public DSResponse fetch(DSRequest dsRequest) throws Exception { long clientId = (Long)dsRequest.getCriteria().get("CLIENT_ID"); String appType = (String) dsRequest.getCriteria().get("PRODUCT_ID"); String operationID = dsRequest.getOperationId(); DSResponse dsResponse = new DSResponse(); if(operationID.equalsIgnoreCase("yearFetch")) { List<Map> yearList = CacheManager.getInstance().getYears(clientId,appType,dsRequest) ; dsResponse.setData(yearList); } else if(operationID.equalsIgnoreCase("monthFetch")) { int year = (Integer)dsRequest.getCriteria().get("YEAR_NUM"); List<Map> monthList = CacheManager.getInstance().getMonths(clientId,appType,year,dsRequest) ; dsResponse.setData(monthList); } return dsResponse; } }
Here are my logs
Code:
Loading module: MarketIntelligence Top URL: http://127.0.0.1:8888/MarketIntelligence.html?gwt.codesvr=127.0.0.1:9997 User agent: FF Remote host: 127.0.0.1:55215 Tab key: 085EC900 Session key: h"7Z3ikau",7}v14 ERROR: Unable to load module entry point class com.sabre.apd.mi.smartgwt.client.MarketIntelligence (see associated exception for details). com.google.gwt.core.client.JavaScriptException: (TypeError): _1.getField(this.getValueFieldName()) is undefined 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.form.ValuesManager.addMember(ValuesManager.java) at com.sabre.apd.mi.smartgwt.client.searchCriteria.ODCriteria.fetchReportInputForm(ODCriteria.java:880) at com.sabre.apd.mi.smartgwt.client.searchCriteria.ODCriteria.<init>(ODCriteria.java:41) at com.sabre.apd.mi.smartgwt.client.layout.SearchCriteriaPane.getSearchCriteria(SearchCriteriaPane.java:383) at com.sabre.apd.mi.smartgwt.client.layout.SearchCriteriaPane.createSearchCriteriaModules(SearchCriteriaPane.java:77) at com.sabre.apd.mi.smartgwt.client.layout.SearchCriteriaPane.<init>(SearchCriteriaPane.java:39) at com.sabre.apd.mi.smartgwt.client.MarketIntelligence.onModuleLoad(MarketIntelligence.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Thread.java:619) ERROR: Failed to load module 'MarketIntelligence' from user agent 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2' at 127.0.0.1:55215.
Comment