Expanding on Bit #26 - Overriding getAttributeDef() to conditionally set an attribute property, you can set a View Object's attribute queryable property simply by calling setQueriable() on its ViewAttributeDefImpl. As explained in Bit #26, you can get the AttributeDef attribute definition by calling getAttributeDef() and passing the attribute index as a parameter. In order to call any of the attribute set...() methods, you will have to cast the AttributeDef interface to an ViewAttributeDefImpl implementation. By the way, did you know that by setting an attribute's queryable property will show or hide a View Criteria Item (i.e. the criterion) based on the attribute on the af:query dialog? Another way to hide the criterion was outlined in Bit #25 - Hiding a View Criteria item based on some condition. It will also show or hide the attribute from the Add Fields drop-down in the Advanced mode of af:query. One last thing: check-out the plethora of set...() methods available in the ViewAttributeDefImpl. As you may have guessed it, pretty much everything that is available declaratively on the Edit Attribute dialog, can be set (or reset) dynamically in your code based on some business condition. For a complete use case, check out the reference listed below.
Example:
/**
* Helper to set an attribute's queriable property.
* Example:
* setQueriable(ViewRowImpl.SOMEFIELDINDEX, something.equals(somethingElse));
*
* @param attribIndex the attribute index
* @param condition the condition (true/false)
*/
protected void setQueriable(int attribIndex, boolean condition) {
// set the attribute queryable as needed
AttributeDef def = super.getAttributeDef(attribIndex);
boolean queryable = condition;
// set/reset queriable only if needed
if (def != null && def.isQueriable() != queryable) {
ViewAttributeDefImpl attributeDef = (ViewAttributeDefImpl)def;
attributeDef.setQueriable(queryable);
}
}
Context:
View Object Implementation Class
References:
http://dstas.blogspot.com/2010/03/set-queryable-property-on-attribute.html
Bits of code related to Oracle's Application Development Framework (ADF). Some of the posts in this blog may seem elementary. They are. Nevertheless, you will be amazed to find out how many beginner ADF practitioners are struggling with basic concepts and sample code. Hopefully they will find some here.
Wednesday, November 24, 2010
Tuesday, November 23, 2010
Bit #26 - Overriding getAttributeDef() to conditionally set an attribute property
You can override ViewObjectImpl's getAttributeDef() method to update an attribute setting, control hint or a custom property. getAttributeDef() is called by the framework each time the attribute's definition needs to be accessed, for example prior to opening an af:query search dialog. In such a case, this may be the ideal place to set a conditional queryable property for example. The argument that is passed to the method indicates the index of the attribute being accessed. You modify the attribute definition by calling super.getAttributeDef() to get the AttributeDef and then call any of its set...() methods. Here is an example:
Example:
@Override
public AttributeDef getAttributeDef(int attribIndex) {
// check for some specific attribute
if (attribIndex == SOME_ATTRIBUTE_INDEX) {
//get the attribute's definition
AttributeDef def = super.getAttributeDef(attribIndex);
// conditionally update some attribute value
// if (someCondition) {
//((ViewAttributeDefImpl)def).set...()
//}
return def;
}
return super.getAttributeDef(attribIndex);
}
Context:
View Object Implementation Class
Example:
@Override
public AttributeDef getAttributeDef(int attribIndex) {
// check for some specific attribute
if (attribIndex == SOME_ATTRIBUTE_INDEX) {
//get the attribute's definition
AttributeDef def = super.getAttributeDef(attribIndex);
// conditionally update some attribute value
// if (someCondition) {
//((ViewAttributeDefImpl)def).set...()
//}
return def;
}
return super.getAttributeDef(attribIndex);
}
Context:
View Object Implementation Class
Monday, November 22, 2010
Bit #25 - Hiding a View Criteria item based on some condition
You can hide or show a View Criteria item (i.e. a criterion), based on some business logic condition by calling setProperty() on an oracle.jbo.ViewCriteriaItem. The method accepts a ViewCriteriaItemHints parameter indicating the view criteria item property to set - in this case CRITERIA_RENDERED_MODE - and a second ViewCriteriaItemHints parameter indicating the property value - in this case any of the CRITERIA_RENDERED_MODE_BOTH, CRITERIA_RENDERED_MODE_BASIC, CRITERIA_RENDERED_MODE_ADVANCED, CRITERIA_RENDERED_MODE_NEVER, CRITERIA_RENDERED_MODE_DEFAULT. To hide or show a criterion, you will have to look for it by iterating through all the criteria rows and all the criteria items for each row. Once found, call setProperty() to set its render mode. Here is an example helper method that illustrates this case.
Example:
/**
* Hides a view criterion.
* Example: The following will hide the SourcePolicyNbr criterio if the condition
* is true. If the condition is false, it will show the criterio in BOTH basic and
* advanced.
*
* hideCriteriaItem("SomeCriteria", "SomeCriteriaItem",
* someCondition==true, ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_BOTH);
*
*
* @param viewCriteriaName the view criteria name
* @param criteriaItemName the criterio name
* @param condition the HIDE condition
* @param showHint the SHOW hint
*/
protected void hideCriteriaItem(String viewCriteriaName,
String criteriaItemName, boolean condition,
String showHint) {
if (viewCriteriaName != null) {
ViewCriteria v = this.getViewCriteria(viewCriteriaName);
if (v != null) {
boolean found = false;
while (v.hasNext() && !found) {
ViewCriteriaRow vcr = (ViewCriteriaRow)v.next();
if (vcr != null) {
ViewCriteriaItem[] vcis = vcr.getCriteriaItemArray();
if (vcis != null && vcis.length > 0) {
for (int j = 0; j < vcis.length && !found; j++) {
ViewCriteriaItem vci = vcis[j];
if (vci != null && criteriaItemName != null &&
criteriaItemName.equals(vci.getName())) {
found = true;
vci.setProperty(ViewCriteriaItemHints.CRITERIA_RENDERED_MODE,
condition ?
ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_NEVER :
showHint);
v.saveState();
}
}
}
}
}
}
}
}
Context:
View Object Implementation Class
Example:
/**
* Hides a view criterion.
* Example: The following will hide the SourcePolicyNbr criterio if the condition
* is true. If the condition is false, it will show the criterio in BOTH basic and
* advanced.
*
* hideCriteriaItem("SomeCriteria", "SomeCriteriaItem",
* someCondition==true, ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_BOTH);
*
*
* @param viewCriteriaName the view criteria name
* @param criteriaItemName the criterio name
* @param condition the HIDE condition
* @param showHint the SHOW hint
*/
protected void hideCriteriaItem(String viewCriteriaName,
String criteriaItemName, boolean condition,
String showHint) {
if (viewCriteriaName != null) {
ViewCriteria v = this.getViewCriteria(viewCriteriaName);
if (v != null) {
boolean found = false;
while (v.hasNext() && !found) {
ViewCriteriaRow vcr = (ViewCriteriaRow)v.next();
if (vcr != null) {
ViewCriteriaItem[] vcis = vcr.getCriteriaItemArray();
if (vcis != null && vcis.length > 0) {
for (int j = 0; j < vcis.length && !found; j++) {
ViewCriteriaItem vci = vcis[j];
if (vci != null && criteriaItemName != null &&
criteriaItemName.equals(vci.getName())) {
found = true;
vci.setProperty(ViewCriteriaItemHints.CRITERIA_RENDERED_MODE,
condition ?
ViewCriteriaItemHints.CRITERIA_RENDERED_MODE_NEVER :
showHint);
v.saveState();
}
}
}
}
}
}
}
}
Context:
View Object Implementation Class
Thursday, November 18, 2010
Bit #24 - Displaying Application Module Pool Statistics
You can display statistics related to your Application Module Pools by calling dumpPoolStatistics() on a oracle.jbo.common.ampool.ApplicationPool object. You can acquire an ApplicationPool object by calling getResourcePool() on a oracle.jbo.common.ampool.PoolMgr object and specifying the name of the application module pool name. So, how do you get a PoolMgr object? Just call the static PoolMgr.getInstance(). Finally, you can get the pool name by calling getResourcePoolKeys() on the PoolMgr and enumerating the pools managed by the pool manager. Here is an example:
Example:
// helper to dump pool statistics to log
private void dumpAMPoolStatistics() {
// get the pool manager
PoolMgr poolMgr = PoolMgr.getInstance();
// get the pools managed
Enumeration keys = poolMgr.getResourcePoolKeys();
if (keys != null) {
if (keys.hasMoreElements()) {
// may manage many pools, we will get the name of first one managed
String poolname = (String)keys.nextElement();
System.out.println("AM pool name: " + poolname);
// get the AM pool
ApplicationPool pool =
(ApplicationPool)poolMgr.getResourcePool(poolname);
// log AM pool diagnostics
PrintWriter out = new PrintWriter(System.out, true);
pool.dumpPoolStatistics(new PrintWriter(out));
out.flush();
}
}
}
The helper function above, when added to your application module will display - upon calling it, the AM statistics in the log window as it is shown below.
Context:
BC Implementation Class
References:
83. Dump Application Module Pooling Statistics Servlet
Example:
// helper to dump pool statistics to log
private void dumpAMPoolStatistics() {
// get the pool manager
PoolMgr poolMgr = PoolMgr.getInstance();
// get the pools managed
Enumeration keys = poolMgr.getResourcePoolKeys();
if (keys != null) {
if (keys.hasMoreElements()) {
// may manage many pools, we will get the name of first one managed
String poolname = (String)keys.nextElement();
System.out.println("AM pool name: " + poolname);
// get the AM pool
ApplicationPool pool =
(ApplicationPool)poolMgr.getResourcePool(poolname);
// log AM pool diagnostics
PrintWriter out = new PrintWriter(System.out, true);
pool.dumpPoolStatistics(new PrintWriter(out));
out.flush();
}
}
}
The helper function above, when added to your application module will display - upon calling it, the AM statistics in the log window as it is shown below.
Context:
BC Implementation Class
References:
83. Dump Application Module Pooling Statistics Servlet
Subscribe to:
Posts (Atom)