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);
}