Sunday, January 20, 2013

How to change view criteria at run time

How to change ViewCriteria At runtime

Sometime we get requirement to change the add or remove attribute to query panel at runtime.
This post will help everybody to achieve that functionality.

Idea is just to play around the query-able attribute of viewobject at runtime. you just have to set it true /false.

    protected void setQueriable(ViewObject vo, String attributeName, boolean condition) {
         // set the attribute queryable as needed
         // getting the ELContext from faces context
         // get application from faces context
       
         AttributeDef def = vo.getAttributeDef(vo.getAttributeIndexOf(attributeName));
         boolean queryable = condition;

         // set/reset queriable only if needed
         if (def != null && def.isQueriable() != queryable) {
             AttributeDefImpl attributeDef = (AttributeDefImpl)def;
             attributeDef.setQueriable(queryable);
             attributeDef.registerDefObject();
         }
    
}

This piece of code it responsible for adding and removing attribute from  af:quereyPanel.

 
 
 
 


Find application source here ChangeCriteriaAtRuntime