Trying to keep the search criteria in the session and stubborn taskflow outdoors

I have a page within a delimited taskflow on which the user can search. I use ViewCriteria and af:query.
I can get the taskflow anytime, but when I return to my search criteria are still empty. I don't want to. I tried the following:

a custom queryListener that calls saveState() so that we remember the search criteria (I also put a boolean session to remember whether there were non-empty search criteria):
<af:query id="qryId1" disclosed="true" 
                          model="#{bindings.StandaardFilterQuery.queryModel}"
                          value="#{bindings.StandaardFilterQuery.queryDescriptor}"
                          queryListener="#{reinigingsRechtBean.onQuery}"
                          queryOperationListener="#{reinigingsRechtBean.processQueryOperation}"
                          displayMode="compact" headerText="blaaa" 
                          resultComponentId="::t1"
                          visible="#{reinigingsRechtBean.showFilter}" 
                          saveQueryMode="hidden" styleClass="querypanel"
                          maxColumns="1">
public void onQuery(QueryEvent queryEvent) {
        // zet het filter standaard op nonactief
        filterActief = false;

        QueryDescriptor queryDescriptor = queryEvent.getDescriptor();
        DCBindingContainer bc = FacesUtils.getBindings();
        Object execBinding = bc.findExecutableBinding("StandaardFilterQuery");
        ViewCriteria vc =
            JUSearchBindingCustomizer.getViewCriteria((DCBindingContainer)execBinding,
                                                      queryDescriptor.getName());
        Variable[] variables = vc.getVariableManager().getDeclaredVariables();

        //         loop door de variabelen en kijk of er 1 een waarde heeft.
        //         zoja dan markeren we het filter als actief.
        //         kunnen we dat aan de gebruiker melden
        for (Variable o : variables) {
            System.out.println(o.getColumnName());
            System.out.println(vc.getVariableManager().getVariableValue(o));
            if (vc.getVariableManager().getVariableValue(o) != null) {
                filterActief = true;
            }
        }
        // raarheid, deze methode wist de waardes die we hierboven uitlezen.
        // dus niet boven de loop zetten want daar zie je ze dan niet meer
        vc.saveState();

        
        // voer nog wel de query uit, anders krijg je geen gegevens :)
        FacesUtils.invokeMethodExpression("#{bindings.StandaardFilterQuery.processQuery}",
                                          Object.class, QueryEvent.class,
                                          queryEvent);

    }
That part works. I leave the taskflow and enter again and see my values. Yay! This feature breaks the "reset" button but reset() goes into its last saved state. I want to "reset" to clear the values and research. So I created this:
    public void processQueryOperation(QueryOperationEvent event) {
        if (event.getOperation().equals(event.getOperation().RESET)) {
            QueryDescriptor queryDescriptor = event.getDescriptor();
            DCBindingContainer bc = FacesUtils.getBindings();
            Object execBinding =
                bc.findExecutableBinding("StandaardFilterQuery");
                ViewCriteria vc =
                    JUSearchBindingCustomizer.getViewCriteria((DCBindingContainer)execBinding,
                                                              queryDescriptor.getName());
                Variable[] variables =
                    vc.getVariableManager().getDeclaredVariables();
                for (Variable o : variables) {
                    vc.getVariableManager().setVariableValue(o, null);
                }
                
                //JUSearchBindingCustomizer.applyNamedCriteria(bc, queryDescriptor.getName());
                // saveState() hoeven we volgens mij niet uit te voeren want de onQuery zal ook afgaan en die doet een saveState()
                vc.saveState(); // toch maar wel
                FacesUtils.getRRAppModuleImpl().getMoeReinigingsRechtRO().applyViewCriteria(vc);
        }
    }
When I press reset, I catch the ViewCriteria, empty values, save the State and even to apply the Victoria Cross to the viewObject. However, the af: query indicates the criteria I entered before AND the search is made to these criteria.
When I loop through the values of ViewCriteria they all void in the onQuery that is executed immediately after processQueryOperation(), but still it is ignored.

What I am doing wrong?
(Jdeveloper 11.1.1.3)

Wendy,

Here's one that is generic

    public void onQueryOperation(QueryOperationEvent queryOperationEvent) {

        if (queryOperationEvent.getOperation().equals(queryOperationEvent.getOperation().RESET)) {
            QueryDescriptor queryDescriptor =
                queryOperationEvent.getDescriptor();
            DCBindingContainer bc =
                (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
            Object execBinding =
                bc.findExecutableBinding("queryEmployeesByDepartmentOrJobIdQuery");
            ViewCriteria vc =
                JUSearchBindingCustomizer.getViewCriteria((DCBindingContainer)execBinding,
                                                           queryDescriptor.getName());
            Row rw = vc.getCurrentRow();
            String[] attrNames = rw.getAttributeNames();

            for (String name : attrNames) {
                if(rw.getAttribute(name)!=null){
                    rw.setAttribute(name, null);
                }
            }

            vc.saveState();
        }

        //--------------------------------------
        FacesContext fctx = FacesContext.getCurrentInstance();
        ELContext elctx = fctx.getELContext();
        ExpressionFactory exprFactory =
            fctx.getApplication().getExpressionFactory();

        MethodExpression me =
            exprFactory.createMethodExpression(elctx, "#{bindings.queryEmployeesByDepartmentOrJobIdQuery.processQueryOperation}",
                                               Object.class,
                                               new Class[] { QueryOperationEvent.class });
        me.invoke(elctx, new Object[] { queryOperationEvent });
    }
}

Frank

Tags: Java

Similar Questions

Maybe you are looking for