ADF修改默認filter查詢將%改爲%%方式

    public static void customQuery(QueryEvent queryEvent,String queryProcess){
        FilterableQueryDescriptor queryDescriptor = (FilterableQueryDescriptor) queryEvent.getDescriptor(); 
            ConjunctionCriterion cc = queryDescriptor.getFilterConjunctionCriterion(); 
            List<Criterion> lc = cc.getCriterionList(); 
            for(Criterion cr : lc){
                AttributeDescriptor attr = ((AttributeCriterion) cr).getAttribute();
                Object value = ((AttributeCriterion) cr).getValue();
                if(attr.getType().equals(String.class)){
                    if(value != null){
                         ((AttributeCriterion) cr).setValue("%" + value + "%");
                     }    
                }
            }
            invokeEL(queryProcess,new Class[]{QueryEvent.class},new Object[]{queryEvent});
            for(Criterion cr : lc){
                AttributeDescriptor attr = ((AttributeCriterion) cr).getAttribute();
                Object value = ((AttributeCriterion) cr).getValue();
                if(attr.getType().equals(String.class)){
                    if(value != null){
                         ((AttributeCriterion) cr).setValue(value.toString().replace("%", ""));
                     }    
                }
            } 
    }
    
    public static Object invokeEL(String el, Class[] paramTypes,Object[] params){
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ELContext eLContext = facesContext.getELContext();
        ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
        MethodExpression exp = expressionFactory.createMethodExpression(eLContext, el, Object.class, paramTypes);
        return exp.invoke(eLContext, params);
    }

調用的地方爲以下,比如通過一個按鈕點擊事件,其中queryProcess參數爲table組件中queryListener屬性的值,現在如今修改爲以下自定義方式

    public void queryMyOrder(QueryEvent queryEvent) {        
        String queryProcess = "#{bindings.TPurchasedProductsView1Query.processQuery}";
        ADFUtils.customQuery(queryEvent, queryProcess);        
    }


發佈了51 篇原創文章 · 獲贊 17 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章