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