Reputation: 309
I'm using JDeveloper version: 11.1.2.0.0
In a page that is a jsff I have an af:query component. The query component is connected to a table like below:
<af:query .../>
<af:table .../>
When I go to a page that is not in the same bounded task flow and then back again to the original page, all the values that were entered into the query are cleared. Is there any good way of stopping this? I thought the query values would be stored in the View Object Instance but maybe that's not the case.
When I use a only table but with filtering the values in the filter stays when I navigate back forth.
I've tried a few things, like for example trying to store the Querydescriptor in a bean but can't get it to work.
This is the code I use to get the values when the user makes a search:
/**Custom Query Listener-Using QueryDescriptor
* @param queryEvent
*/
public void customQueryProcess(QueryEvent queryEvent) {
QueryDescriptor qd = queryEvent.getDescriptor();
ConjunctionCriterion conCrit = qd.getConjunctionCriterion();
//access the list of search fields
List<Criterion> criterionList = conCrit.getCriterionList();
//iterate over the attributes to find FromDate and ToDate
for (Criterion criterion : criterionList) {
AttributeDescriptor attrDescriptor = ((AttributeCriterion)criterion).getAttribute();
String name = attrDescriptor.getName();
String value = (String)((AttributeCriterion)criterion).getValues().get(0);
queryValues.put(name, value);
}
/**Process default query listener*/
Context.invokeEL("#{bindings.FlettefeltVCQuery.processQuery}", new Class[] { QueryEvent.class },
new Object[] { queryEvent });
}
The problem now is how to apply the saved values when the user returns to the page? I've tried to introduce a custom value property in my bean where i change the values. This results in strange behaviour. In my table I get the rigth number of rows for a certain query, but they're the worng rows. They seem to be just the first rows in the table. This is the code that I've tried:
public QueryDescriptor getCustomQueryDescriptor() {
QueryDescriptor query = (QueryDescriptor)Context.evaluateEL("#{bindings.FlettefeltVCQuery.queryDescriptor}");
ConjunctionCriterion conCrit = query.getConjunctionCriterion();
List<Criterion> criterionList = conCrit.getCriterionList();
for (Criterion criterion : criterionList) {
AttributeDescriptor attrDescriptor = ((AttributeCriterion)criterion).getAttribute();
String name = attrDescriptor.getName();
AttributeCriterion ac = (AttributeCriterion)criterion;
if (queryValues.containsKey(name)) {
List values = ac.getValues();
values.clear();
values.set(0, queryValues.get(name));
}
}
return query;
}
Upvotes: 0
Views: 5698
Reputation: 309
I found a solution that solved my problem. The key to the solution was to set the property InitialQueryOverridden on the search region in the bindings layer to true. This stops the query from executing every time the page is entered. However, if query automatically is set to true on the View criteria it will perform a query the first time the page is entered in a session.
This solves the problem with the rows in the table. They now don't change as you leave and enter the page. However, the values in the query dissapear. To solve this I wrote the following code in a session bean.
public void customQueryProcess(QueryEvent queryEvent) {
qd = queryEvent.getDescriptor();
ConjunctionCriterion conCrit = qd.getConjunctionCriterion();
//access the list of search fields
List<Criterion> criterionList = conCrit.getCriterionList();
//iterate over the attributes to find FromDate and ToDate
for (Criterion criterion : criterionList) {
AttributeDescriptor attrDescriptor = ((AttributeCriterion)criterion).getAttribute();
String name = attrDescriptor.getName();
Object value = ((AttributeCriterion)criterion).getValues().get(0);
queryValues.put(name, value);
}
/**Process default query listener*/
Context.invokeEL("#{bindings.FlettefeltVCQuery.processQuery}", new Class[] { QueryEvent.class },
new Object[] { queryEvent });
}
public QueryModel getCustomQueryModel() {
System.out.println("getCustomQueryModel");
QueryModel model = (QueryModel)Context.evaluateEL("#{bindings.CustomersVCQuery.queryModel}");
List<QueryDescriptor> systemQueries = model.getSystemQueries();
for(QueryDescriptor query : systemQueries){
ConjunctionCriterion conCrit = query.getConjunctionCriterion();
List<Criterion> criterionList = conCrit.getCriterionList();
for (Criterion criterion : criterionList) {
AttributeDescriptor attrDescriptor = ((AttributeCriterion)criterion).getAttribute();
String name = attrDescriptor.getName();
AttributeCriterion ac = (AttributeCriterion)criterion;
if(queryValues.containsKey(name)){
List values = ac.getValues();
values.clear();
values.set(0, queryValues.get(name));
}
}
}
return model;
}
The code is connected to the query component in my jsff file, in the following way:
<af:query id="qryId1" headerText="My query" disclosed="true"
model="#{myQueryBean.customQueryModel}"
queryListener="#{myQueryBean.customQueryProcess}"
queryOperationListener="#{bindings.CustomersVCQuery.processQueryOperation}"
resultComponentId="::resId1" saveQueryMode="hidden"
value="#{bindings.CustomersVCQuery.queryDescriptor}"/>
Upvotes: 1