Determining If View Attribute Is From Primary Entity

Send me a mail
 Dive into Oracle ADF   Click to see the XML version of this web page.   (Updated: 2/3/2008; 9:26:03 PM.)
Tips and tricks from Steve Muench on Oracle ADF Framework and JDeveloper IDE

Determining If View Attribute Is From Primary Entity

A customer asked if there is a way to determine whether a view object attribute is from the primary entity for its view object, or not. The three methods in this framework extension class illustrate a method that can get the job done:

package demo.fwkext;
import oracle.jbo.AttributeDef;
import oracle.jbo.server.EntityDefImpl;
import oracle.jbo.server.ViewAttributeDefImpl;
import oracle.jbo.server.ViewObjectImpl;
public class CustomViewObjectImpl extends ViewObjectImpl {
  private boolean isAttributeFromPrimaryEntity(AttributeDef attrDef) {
    EntityDefImpl[] defs = getEntityDefs();
    return ((defs != null) && (defs.length > 0))
    ? (((ViewAttributeDefImpl) attrDef).getEntityDef() == defs[0]) : false;
  }
  public boolean isAttributeFromPrimaryEntity(int attrSlot) {
    return isAttributeFromPrimaryEntity(getAttributeDef(attrSlot));
  }
  public boolean isAttributeFromPrimaryEntity(String attrName) {
    return isAttributeFromPrimaryEntity(findAttributeDef(attrName));
  }
}

You can use this method by passing it either an attribute name as a string, or an attribute integer index "slot number". It works by comparing the view attribute definitions EntityDefImpl object with the first EntityDefImpl object in the ViewObject definition (if there is one).



© Copyright 2008 Steve Muench. Click here to send an email to the editor of this weblog.
Last update: 2/3/2008; 9:26:03 PM.