Hi Isomorphic,
in order to solve a more advanced use case (using v12.0p_2019-02-24), I was changing my FETCH operationBinding .ds.xml criteria from this, which is working fine:
The session values here are set before in the application via servletRequest.getSession().setAttribute().
I now wanted to change this syntax (taken from here) to the more advanced one also listed in the link. This fails for me in many ways.
Please see the sample and the two operationBindings there. They should do the same, but trigger very different codepath IMHO. Once MySQLDataSource.executeFetch() is called (good), once it is not (bad).
If it is called, no Velocity replace takes place (bad). It it is not called, an Exception is thrown, perhaps because of some noVariable -> null subsequent fault (bad).
Please see the .ds.xml comments and the presence or absence of the MySQLDataSource log messages depending on the button clicked.
I'd expect to run a query in both cases and also the SQL statements to be the same.
BuiltInDS.java:
MySQLDataSource.java:
employees.ds.xml (see comments):
Best regards
Blama
in order to solve a more advanced use case (using v12.0p_2019-02-24), I was changing my FETCH operationBinding .ds.xml criteria from this, which is working fine:
Code:
<operationBinding operationType="fetch" operationId="..." requiresRole="..." outputs="..."> <criteria fieldName="RESELLER_ID" value="$session.authenticatedUserResellerID" /> <criteria fieldName="USER_ID" value="$session.authenticatedUserID" /> </operationBinding>
I now wanted to change this syntax (taken from here) to the more advanced one also listed in the link. This fails for me in many ways.
Please see the sample and the two operationBindings there. They should do the same, but trigger very different codepath IMHO. Once MySQLDataSource.executeFetch() is called (good), once it is not (bad).
If it is called, no Velocity replace takes place (bad). It it is not called, an Exception is thrown, perhaps because of some noVariable -> null subsequent fault (bad).
Please see the .ds.xml comments and the presence or absence of the MySQLDataSource log messages depending on the button clicked.
I'd expect to run a query in both cases and also the SQL statements to be the same.
BuiltInDS.java:
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.Version; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.data.AdvancedCriteria; import com.smartgwt.client.data.Criterion; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.SortSpecifier; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.PageKeyHandler; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.VLayout; public class BuiltInDS implements EntryPoint { private VLayout mainLayout; public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new PageKeyHandler() { public void execute(String keyName) { SC.showConsole(); } }); mainLayout = new VLayout(20); mainLayout.setWidth100(); mainLayout.setHeight100(); { IButton recreateBtn = new IButton("Recreate fetchBadVelocityNoException"); recreateBtn.setWidth(250); recreateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { recreate("fetchBadVelocityNoException"); } }); mainLayout.addMember(recreateBtn); } { IButton recreateBtn = new IButton("Recreate fetchBadNoVelocityException"); recreateBtn.setWidth(250); recreateBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { recreate("fetchBadNoVelocityException"); } }); mainLayout.addMember(recreateBtn); } mainLayout.draw(); } private void recreate(String fetchOperation) { Window w = new Window(); w.setWidth("95%"); w.setHeight("95%"); w.setMembersMargin(0); w.setModalMaskOpacity(70); w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")"); w.setTitle("Problem with Velocity and .ds.xml RequestModifier" + w.getTitle()); w.setShowMinimizeButton(false); w.setIsModal(true); w.setShowModalMask(true); w.centerInPage(); final ListGrid employeesGrid = new ListGrid(); employeesGrid.setHeight100(); employeesGrid.setAutoFetchData(false); employeesGrid.setDataSource(DataSource.get("employees")); employeesGrid.setFetchOperation(fetchOperation); ListGridField employeeId = new ListGridField("EmployeeId"); ListGridField name = new ListGridField("Name"); ListGridField gender = new ListGridField("Gender"); ListGridField job = new ListGridField("Job"); employeesGrid.setFields(employeeId, name, gender, job); employeesGrid.setSort(new SortSpecifier[] { new SortSpecifier(name.getName(), SortDirection.ASCENDING) }); employeesGrid.fetchData(new AdvancedCriteria(new Criterion(name.getName(), OperatorId.LESS_OR_EQUAL, "L"))); w.addItem(employeesGrid); w.show(); } }
Code:
package com.smartgwt.sample.server.listener; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.log.Logger; import com.isomorphic.sql.SQLDataSource; public class MySQLDataSource extends SQLDataSource { private static final long serialVersionUID = -2103887355803373948L; Logger log = new Logger(SQLDataSource.class.getName()); @Override public DSResponse executeFetch(DSRequest request) throws Exception { request.addToTemplateContext("EmployeeType", "full time"); log.info("Added velocity variable EmployeeType"); log.info("HTTP parameter isc_v is " + request.getHttpServletRequest().getParameter("isc_v")); DSResponse fetchResponse = super.executeFetch(request); return fetchResponse; } }
Code:
<DataSource xmlns="lmscompany/ds" serverConstructor="com.smartgwt.sample.server.listener.MySQLDataSource" ID="employees" serverType="sql" tableName="employeeTable" recordName="employee" testFileName="/examples/shared/ds/test_data/employees.data.xml" titleField="Name" > <fields> <field name="userOrder" title="userOrder" type="integer" canEdit="false" hidden="true"/> <field name="Name" title="Name" type="text" length="128"/> <field name="EmployeeId" title="Employee ID" type="integer" primaryKey="true" required="true"/> <field name="ReportsTo" title="Manager" type="integer" required="true" foreignKey="employees.EmployeeId" rootValue="1" detail="true"/> <field name="Job" title="Title" type="text" length="128"/> <field name="Email" title="Email" type="text" length="128"/> <field name="EmployeeType" title="Employee Type" type="text" length="40"/> <field name="EmployeeStatus" title="Status" type="text" length="40"/> <field name="Salary" title="Salary" type="float"/> <field name="OrgUnit" title="Org Unit" type="text" length="128"/> <field name="Gender" title="Gender" type="text" length="7"> <valueMap> <value>male</value> <value>female</value> </valueMap> </field> <field name="MaritalStatus" title="Marital Status" type="text" length="10"> <valueMap> <value>married</value> <value>single</value> </valueMap> </field> </fields> <operationBindings> <operationBinding operationType="fetch" operationId="fetchBadNoVelocityException"> <criteria fieldName="OrgUnit" value="Management" /> <!-- Good! --> <criteria fieldName="EmployeeStatus" value="$dsRequest.dataSourceName" /> <!-- Good! --> <criteria fieldName="EmployeeStatus" value="$httpParameters.isc_v" /> <!-- Good --> <criteria fieldName="EmployeeType" value="$EmployeeType" /> <!-- Null / Exception --> </operationBinding> <operationBinding operationType="fetch" operationId="fetchBadVelocityNoException"> <criteria _constructor="AdvancedCriteria" operator="and"> <criteria> <Criterion fieldName="OrgUnit" operator="equals" value="Management" /> <!-- Good! --> <Criterion fieldName="EmployeeStatus" operator="equals" value="$dsRequest.dataSourceName" /> <!-- Not replaced --> <Criterion fieldName="EmployeeStatus" operator="equals" value="$httpParameters.isc_v" /> <!-- Not replaced --> <Criterion fieldName="EmployeeType" operator="equals" value="$EmployeeType" /> <!-- Not replaced --> </criteria> </criteria> </operationBinding> </operationBindings> </DataSource>
Blama
Comment