Wednesday, March 31, 2010

Set Queryable Property on Attribute Programmatically

Have you ever thought of programmatically changing the Queryable property of an Attribute in your View Object??

Download the sample application

Lets say that we have the following case:

We have a View Object (VO) with one view Criteria (VC). All attributes have by default set the 'Queryable' property to true. We are fine so far.

Then, the rain comes... We thought that attribute 'A' should become queryable only if an external parameter 'paramA' has value to 'true'.

Well, it is fairly easy to change the property..
In the sample application i have placed the following code in the VO Impl java class.

* Changes the value of the Queryable property of an Attribute of this ViewObject.
* @param attrName String the name of the attribute.
* @param isQueryable Boolean the value to be set.
public void changeQueryableProperty(String attrName, Boolean isQueryable){

ViewAttributeDefImpl[] vAttrDefImpls=this.getViewAttributeDefImpls();
int attrIndex=this.getAttributeIndexOf(attrName);

// For those of you that have noticed
//that getViewAttributeDefImpls() is
//for internal use only.
//use the following code:

// AttributeDef[] attrs = this.getAttributeDefs();
// int attrIndex=this.getAttributeIndexOf(attrName);
// ViewAttributeDefImpl vida=(ViewAttributeDefImpl)attrs[attrIndex];
// vida.setQueriable(isQueryable);


In the example as you will see, i have placed two pages

NOTE: this is just an example of doing things in order to illustrate the less code to be written... The Declarative way.... You spin my head round round... :D

1) Main
2) Second

When we are navigating from Main to Second page we pass a pageFlowScope parameter and we are actually declaring whith attribute will be queryable or not.

I have exposed the method above in the client interface and created a methodAction in the page Defintion

Then I placed an InvokeAction in the Executables section of Seconds' pageDef, which will invoke changeQueryableProperty. As a refresh condition i placed 'prepareModel' option in order to be invoked during the initialisation of the iterators.

Download the sample application

Enjoy Life the way you Wantd!


  1. Nice post!!
    You already have a code follower ;)

  2. Nice Post. I have another requirement. How do we make the attribute non-queryable not based on any condition, kind of based on a properties file?

  3. Hi Anonymous,
    Well, if you are going to use properties file, you will to read the properties file. This post will be helping you. But you have to search on the internet for how to read property files with java.

  4. Hi Dimitrios, I solved the problem by executing the method in executeQueryForCollection method in the VO Impl. My requirement was to globally manage some of the VO's attributes by the help of properties file. Thanks for your post. It was really of help.




Related Posts Plugin for WordPress, Blogger...