Hello all:
Here’s an interesting wrinkle I just discovered. The filter manualApplyRequired option is used to ensure that the user presses “Search” so that the filter does not execute when a screen is first loaded.
This works great, but in my case it interfered with my own use of the loader. I have an extra filter that I wrote based on a dropdown selection in addition to the normal filter. When I set manualApplyRequired= “true”, my own loader stopped loading anything.
After stepping through all the code, I discovered that manualApplyRequired = “true” was implemented by adding an extra jpql condition to the loader query of “where 0<>0”. That interfered with my second use of the loader and my own filter, unless the user had previously done a filter-based search and pressed the “Search” key.
I also discovered that the actual filter object leaves parameters defined if they have been used, even if you clear the value afterwards. For example, if you filter on field “name” and then clear the filter value for “name”, the paramenter “name” still exists in the loader parameters map. When you then try to do your own load, you get an SQL error because the “name” parameter is not in the query any longer.
The solution is to use:
loader.setParameters(new HashMap<>()); // clears out the parameter map removing filter params
loader.setParameter("myParam", myValue); // set my parameter
loader.setCondition(null); // clears out the JPQL "where 0<>0" from manualApplyRequired="true"
loader.load();
I did not see this in the documentation anywhere. Did I miss it?
I hope somebody else finds this useful.