Tuesday, April 23, 2013

Display Data in UI without ADF View Object


In General we will design user bound interface by dragging an item from data control panel  and dropping it on a page  as specific UI component . when you use data controls to create a UI component , jdev automatically created the necessary bindings and objects .Data controls consists of various ADF view objects that can be used in the UI to display some data in tabular form . In this post i will explain about how to bring some data in UI without having to create view object .

The component which i am using for this is UIXIterator  .UIXIterator is a component that does iteration . we can go through this with an example


Add the following code in your Managed Bean :

private ArrayList results = new ArrayList();

    public void setResults(ArrayList results) {
        this.results = results;
    }

    public ArrayList getResults() {

               results = this.getData();
               return results;
    }

      public ArrayList getData() {

        ArrayList al;
        al = new ArrayList();
        al.add("Sri");
        al.add("Prasad");
        al.add("John");

        al.add("Marie");
        System.out.println(al);
        return al;
    }

Add this code in ur ADF page

<af:iterator value="#{pageFlowScope.managedBean.results }" var="row" id="i1"
                 varStatus="i">
      <af:commandLink id="cl21">
        <af:outputText value="#{row}" id="ot1"/>
      </af:commandLink>
 </af:iterator>

Here af:iterator does the trick . whenever the page is loaded it looks for the results property in the managed bean and the corresponding method is being called and results populated in the arraylist. so inside the loop we can access the values using the var property of af:iterator. Interesting point is  <af:forEach> address the same issue, but it will not be used with collection model ,JSF data model.It also cannot be bound to EL expressions.

In the same way you can build your data in your collection and display it in the UI without binding into any data control.

Final output would be :

Sri
Prasad
John
Marie





No comments:

Post a Comment