Problem to pass criteria to datasource for nested DynamicForm

Hi,

This sort of problem has been annoying me for 3 days. I had problem to pass additional criteria to FilterEditor/FilterBuilder, and have problem to pass criteria to nested DynamicForm. The problem is so strange, from the RPC log it shows that the criteria is messed up, instead of passing in the right criteria, some other values are passed in. Apart from it, the DynamicForm gets loaded twice, failure for the first time, and success for the second time, so when it’s loaded, everything looks ok except an error popup.

the first row expansion is normally ok, but it’s almost guaranteed to have problems afterwards.

This nested DynamicForm is used to edit the record. When the record gets loaded, the form will have some SelectItems that contain datasouce generated options.

Here’s some code

/** this is called inside the [b]getExpansionComponent(final ListGridRecord record)[/b]
public VLayout getEditForm(ListGridRecord record) {
....
/** all these values are correctly retrieved **/		
		String userId = loginUserMap.get("pk_user_id");
		String transportRole = loginUserMap.get("transport_role");
		String parentConsignor = record.getAttribute("parent_consignor");
		String parentCarrier = record.getAttribute("parent_carrier");
		String accountCode = record.getAttribute("account_code");
...
...
		
/** here instantiates a selectitem and criteria to retrieve the option list **/
		final Criteria criAccountCode = new Criteria();
		criAccountCode.addCriteria("parent_user", userId);
		criAccountCode.addCriteria("parent_carrier", parentCarrier);
		criAccountCode.addCriteria("parent_consignor", parentConsignor);

		selectAccountCode = new SelectItem("account_code", "Account Code");
		selectAccountCode.setPickListCriteria(criAccountCode);
		selectAccountCode.setOptionDataSource(dsUserCarrier);
		selectAccountCode.setDisplayField("account_code");
		selectAccountCode.setValueField("account_code");
		selectAccountCode.setRequired(true);
		selectAccountCode.setOptionOperationId("find.account.codes.for.login.user");
....
....

/** edit the record when it's 
		layoutForm.addDrawHandler(new DrawHandler() {
			public void onDraw(DrawEvent event) {
/** pass in the selected grid record to populate corresponding values **/
				formManager.editRecord(record);
			}
		});

the datasource.ds.xml

        <operationBinding operationType="fetch" operationId="find.account.codes.for.login.user">
            <selectClause>
                *
            </selectClause>
            <tableClause>
                transact_user_carrier
            </tableClause>
            <whereClause>
                parent_user = $criteria.parent_user
                and parent_carrier = $criteria.parent_carrier
                and parent_consignor = $criteria.parent_consignor
            </whereClause>
        </operationBinding>

For the first row expansion, the form is loaded only once, but if there’s a problem it gets loaded twice, and the second load is always correct.

The success RPC log (Request)

{
    "actionURL":"http://127.0.0.1:8888/transact/sc/IDACall", 
    "showPrompt":false, 
    "prompt":"Finding Records that match your criteria...", 
    "transport":"xmlHttpRequest", 
    "promptStyle":"dialog", 
    "bypassCache":true, 
    "data":{
        "criteria":{
            "parent_user":"1", 
            "parent_carrier":"1", 
            "parent_consignor":"1"
        }, 
        "operationConfig":{
            "dataSource":"transact_user_carrier", 
            "repo":null, 
            "operationType":"fetch", 
            "textMatchStyle":"startsWith"
        }, 
        "startRow":0, 
        "endRow":75, 
        "componentId":"isc_PickListMenu_0", 
        "appID":"builtinApplication", 
        "operation":"find.account.codes.for.login.user", 
        "oldValues":{
            "parent_user":"1", 
            "parent_carrier":"1", 
            "parent_consignor":"1"
        }
    }
}

The FAILURE RPC log (Request)

{
    "actionURL":"http://127.0.0.1:8888/transact/sc/IDACall", 
    "showPrompt":false, 
    "transport":"xmlHttpRequest", 
    "promptStyle":"dialog", 
    "bypassCache":true, 
    "data":{
        "criteria":{
            "account_code":"23456"
        }, 
        "operationConfig":{
            "dataSource":"transact_user_carrier", 
            "repo":null, 
            "operationType":"fetch"
        }, 
        "appID":"builtinApplication", 
        "operation":"find.account.codes.for.login.user", 
        "oldValues":{
            "account_code":"23456"
        }
    }
}

These two messages are generated by one ListGrid row expansion.

See the criteria gets totally messed up in a failure, the ‘account_code:23456’ is actually the value retrieved from the ListGridRecord, but how come it gets into the criteria?

Please help me, thanks!

The second request does not appear to be coming from a SelectItem (not the lack of a componentId). Rather, the log suggests that it is issued programmatically. Try to isolate the actual cause of the second request - it doesn’t appear to be related to the code you’ve posted or interactions you describe.

Thanks Iso.

it’s strange because the first row expansion is usually corret, there will be only one request, and it’s successful. but if this row is collapsed, and expanded again, it runs into that strange 2 requests problem.

I m not sure if it’s related, i solved the ‘row update and removed’ problem that we have discussed yesterday. It was because irrelative criteria was passed into the ListGrid fetchData/filterData. I wrote the functions for 3 different roles of users, each role has different access level and should see different things, so i passed in criteria for all roles, but this caused problem. I tried to give each role exact criteria to filter what they should see, it updates and leaves the record in the ResultSet.

from this it looks like that every criteria in the request will be assessed against the called query, is that right? so i guess in the future i should always give what’s needed for the query, no reservation for queries under different conditions.

I don’t know if the above issue is related to this problem, i’ll try to check if the criteria is defined properly, but still confused how the first request(FAILURE) is issued programmatically. Just to confirm while you said it’s not related to the code i provided and the interaction i described, i guess what you meant is that the code is correct, am i right? if i m, i’ll be focusing on other bits of my code.

Thanks!

Good to hear you found that was adding extra criteria. Yes, adding extra criteria will always be a problem - define only the criteria you actually want to use.

About this extra request - have you considered whether it’s the result of FormItem.fetchMissingValues? Try turning that property off and see if it suppresses the fetch. If it does, consider if there’s a way you can make that fetch work.

Thanks Iso, i’ll try that.

sorry just have more question regarding the ListGrid fetching/filtering, i think i haven’t got the idea about it. i looked at the showcase for several times, but all the examples are simply selecting all records.

how should i implement the functions as described below:

1. A ListGrid to show record based on user role, a relatively complex query will be executed to get the result
What i do is to pass the needed parameters in, and call the operationId by ListGrid.fetchData(criteria)

2. User search for certain records, the query and criteria used here is different from the query in point 1.
What i do here is to define another criteria with all conditions needed for the search, call the operationId by ListGrid.filterData(new_criteria)

Both searches return correct results, but when i edit one record from the initial search, it updates and leaves the record in the resultset; but if i edit a record from the result of the customized search, it updates and disappears(in dev console, the ResultSet debug log shows 'didn’t match filter{devliery_address: abc} something, those criteria are used for the customized search, but not for the first initial search).

My question is after an update, what filter criteria does the ResultSet use to synchronize the cache? if it uses the current criteria, why the customized search doesn’t perform ‘update and display’ correctly?

Sorry for so many questions about the same issue, once i understand the concept hopefully i would be able to handle all these :slight_smile:

Thanks for you help very much!

?

Yes it uses the current criteria, and you’ve already seen the FAQ item about this, and already seen that the ResultSet will log the exact criteria in use, cache sync data returned, and criteria applied to it… so what question do you have that isn’t addressed by this?

but it doesn’t perform that way, did i do anything wrong?

buttonSearch.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				Criteria criConnote = searchForm.getValuesAsCriteria();

				String fetchOperation = "find.consignment.for.today.for.customer.user.by.filter";
				
				String byConnoteNumber = criConnote.getAttribute("connote_number");
				String byDeliveryAddress = criConnote.getAttribute("delivery_address");
				
				if(byConnoteNumber == null) {
					criConnote.addCriteria("connote_number", "%");
				}
				
				if(byDeliveryAddress == null) {
					criConnote.addCriteria("delivery_address", "%");
				}
				
				criConnote.addCriteria("parent_user", "1");
				
				gridConnote.setFetchOperation(fetchOperation);
				gridConnote.filterData(criConnote);
			}
		});
		<operationBinding operationType="fetch" operationId="find.consignment.for.today.for.customer.user.by.filter">
			<tableClause>
				transact_consignment, transact_carrier
			</tableClause>
			<whereClause><![CDATA[
				transact_carrier.pk_carrier_id = transact_consignment.parent_carrier
				AND (
				transact_consignment.parent_user = $criteria.parent_user
				OR account_code IN (SELECT account_code FROM transact_user_carrier WHERE parent_user = $criteria.parent_user))
				AND transact_consignment.connote_number LIKE CONCAT('%',CONCAT($criteria.connote_number,'%'))
				AND transact_consignment.delivery_address LIKE CONCAT('%',CONCAT($criteria.delivery_address,'%'))
				AND DATE(transact_consignment.last_updated) >= DATE($criteria.from_date)
				AND DATE(transact_consignment.last_updated) <= DATE($criteria.to_date)
				]]>
			</whereClause>
		</operationBinding>

the operation called by search button needs parent_user, connote_number, delivery_address, from_date, to_date, but when i edit a record, the row gets removed and these parameters are reported ‘didn’t match filter’, it looks like the ResultSet is not using this operation as its filter.

The ResultSet does not in general use a server-side operation to figure out what records match the criteria (you can see this because of course there aren’t any extra requests to go to the server to run more SQL). The ResultSet simply matches the data returned from the server against the criteria, field by field.

but by saying the ResultSet uses the current critera to filter the returned result, it doesn’t appear to be like that. this is the ResultSet debug log after an update on a customized search result:

didn't match filter: {from_date: Date(11/11/2010),
to_date: Date(11/11/2010),
connote_number: "%",
delivery_address: "%",
parent_user: "1"}

these parameters are used for the customized search

does this affect the result set:

/** this is set at page load **/
gridConnote.setCriteria(criterForInitialLoad);

Yes, setting criteria affects the ResultSet. The ResultSet applies the current criteria to the modified record to see if it should remain in the cache.

This is just a restatement of what we’ve said several times - sorry, no idea what your confusion is.

sorry, i think i didn’t get my question clear. my confusion is that a ResultSet filters results using current criteria, when i do a customized search, i guess the current criteria has been changed to accordingly to perform the search, but when update a record it still disappears from the ListGrid. or put it this way, when a search button is clicked, it implements listGrid.filterData(new_criteria), will this new_criteria be used for the ResultSet as the filter?