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);
vAttrDefImpls[attrIndex].setQueriable(isQueryable);
//UPDATE:
// 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!
Declarativelly!
cheers.