Iterating ViewObject vertically (get all attributes of ViewObject) programmatically

Sharing is Caring

Hello All,
This post talks about a requirement of getting all attributes (column names) of a ViewObject programmatically, Iterating ViewObject vertically.

  • Create a fusion web application and business component using department table

 

  • You can see all attributes in  Departments entity object

 

  • Now to get ViewObject’s attributes name , there is a method written in AMImpl class , see it, i have added a facesMessage to show all names on a Message Board

    /**Method to get all attributes of a viewObject
     * */
public void iterateVoVertically() {
  ViewObjectImpl vo = this.getDepartments1();
  ViewAttributeDefImpl[] attrDefs = vo.getViewAttributeDefImpls();
  int count = 0;
  StringBuilder infoMsg =
    new StringBuilder("<html><body><b><p style='color:red'> Attribute of Department ViewObject are-</p></b>");
  infoMsg.append("<ul>");

for (ViewAttributeDefImpl attrDef : attrDefs) {
byte attrKind =
attrDefs[count].getAttributeKind(); //checks attribute kind for each element in an array of AttributeDefs
if (attrKind != AttributeDef.ATTR_ASSOCIATED_ROW && attrKind != AttributeDef.ATTR_ASSOCIATED_ROWITERATOR) {
String columnName = attrDef.getName();
infoMsg.append("<li> <b>" + attrDef.getName() + "</b></li>");
System.out.println("Column Name-" + columnName);
}
}
infoMsg.append("</ul><br>");
infoMsg.append("</body></html>");
FacesMessage msg = new FacesMessage(infoMsg.toString());
msg.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext.getCurrentInstance().addMessage(null, msg);
}

 

 

  • Now on click of button all attributes of Departments ViewObject are shown in FacesMessage, you can use it in your code
Iterating ViewObject

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

Leave a Reply

Your email address will not be published. Required fields are marked *