Showing posts with label list. Show all posts
Showing posts with label list. Show all posts

Friday, 4 April 2014

ADF : af:table or adf form or adf page taking too much time to load

During the development sometimes we come across this problem. In our case we had a table on a page and it was taking too much time to load, even though there were only one row in the database table but then also it was taking more than enough time to load. After the analysing the problem finally we were able to solved the problem.

The main problem was with the List of Values with SingleSelection which was inserted in the table. In a column we had to show the name in place of the id, so the developer created a List of Values in the viewObject and put it in the table on page. At first it was working fine but later as the number of rows grown in the List of values the list started taking time to load.

The main cause was the number of rows in the list of values. Single selection list of values matches the id with the value and shows values, so inorder to map it needs all the rows, so whenever the table was being load the ListOfValues started to fetch all the rows, and as the number of rows was too much so abviously it was taking too much time. So, we had to replace the list of values but we also had to show the name in place of id. 

So there are many ways to do that : 

1. We can include the name that we have to display in the query of the table itself, because of which we can simply display it in a column.

2. Otherwise we have to use a viewobject with query that returns a less number of rows and better if it returns one row with the id and DisplayName. 
Suppose we have to show Department Name in place of department id in Employees Table. The query will be something like this : SELECT DEPARTMENT_NAME FROM DEPARTMENTS WHERE DEPARTMENT_ID = :DeptIdBind

And then we need to show the display name so we created a transient attribute.
Then in the getter of the transient attribute, get the viewObject and pass the bindVariables and execute the query. The query will return a row and then we can fetch the name from the view object and show it by returning it.

There is a disadvantage of using this method, as the query is executed for all the rows fetched in the table. But page load problem will be solved. 

This may depend on the use case.  For us both worked well.

I will suggest never to use SingleSelection List of Values that contains large number of rows in the page. Not even on the adf form. Because due to that it will take too much time to load.

Thanks for reading. If you have any question, Please feel free to ask.

Friday, 12 April 2013

how to populate data in ADF table from Bean using POJO | Populating af:table using ArrayList

Hi,

This post is about populating af:table from a POJO from the bean.

Suppose we have to show information related to books to the user.
So first we have to understand how we populate a table from a List.
  1. For this we have to create a dataType for storing the data of the book.
  2. For the same, we have created a Class named BookInfo. Here is the code for on the BookInfo class.

    package edittableonpojo.view.dc;
    
    public class BookInfo {
        private String bookDesc;
        private String bookAuthNm;
        private String bookSrNo;
        
        public BookInfo(String bookSrNo,String bookDesc,String bookAuthNm) {
            super();
            this.bookSrNo = bookSrNo;
            this.bookAuthNm = bookAuthNm;
            this.bookDesc = bookDesc;
        }
    
        public void setBookDesc(String bookdesc) {
            this.bookDesc = bookdesc;
        }
    
        public String getBookDesc() {
            return bookDesc;
        }
    
        public void setBookAuthNm(String bookAuthNm) {
            this.bookAuthNm = bookAuthNm;
        }
    
        public String getBookAuthNm() {
            return bookAuthNm;
        }
    
        public void setBookSrNo(String bookSrNo) {
            this.bookSrNo = bookSrNo;
        }
    
        public String getBookSrNo() {
            return bookSrNo;
        }
        
        public String getKey(){
            return this.getBookSrNo();
        }
        
        public String toString(){
            return bookSrNo+"_"+bookAuthNm+"_"+bookDesc;
        }
    }
    

  3. Then we have to create a Bean from which data will be provided to the table. In the constructer of the Bean the code is written to populate the data in the ArrayList. Here is the code of the Bean.

    package edittableonpojo.view.bean;
    
    import edittableonpojo.view.dc.BookInfo;
    
    import java.util.ArrayList;
    
    public class BookBean {
        private ArrayList<BookInfo> bookDtls = new ArrayList<BookInfo>();
    
    
        public BookBean() {
            bookDtls.add(new BookInfo("1A", "The Alchemist", "Paulo Cohelo"));
            bookDtls.add(new BookInfo("2A", "Game Of Thrones", "George R. R. Martin"));
            bookDtls.add(new BookInfo("3A", "Five Point Someone", "Chetan Bhagat"));
            bookDtls.add(new BookInfo("4A", "Harry Potter", "J.K.Rowling"));
            bookDtls.add(new BookInfo("5A", "Wings of Fire", "A.P.J Abdul Kalam"));
        }
    
        public ArrayList<BookInfo> getBookInfo() {
            return bookDtls;
        }
    }
    

  4. Now we have to create a Page where we can show the data of the List. For this, I have created a jspx page and dropped an af:table in which we will show the data and done some styling ;).
  5. The table contains three Columns
    1. Book SrNo.
    2. Author Name.
    3. Book Description
  6. In the Value attribute of the Table from the Property inspector, select the value of the attribute from the bean-like   
<af:table var="row" rowBandingInterval="0" id="t1" value="#{viewScope.BookBean.bookInfo}"
                                  rowSelection="none"
                                  inlineStyle="line-Height: 15px;">

  1. In the Columns drop af:outputText and in the value of the outputText put the value like value="#{row.bookAuthNm}" for showing the Author name , and similarly you have to put values in other rows.
  2. Here is the code of the jspx page.

    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>
        <f:view>
            <af:document title="untitled1.jspx" id="d1">
                <af:form id="f1">
                    <af:panelBox text="Book Details" id="pb1">
                        <f:facet name="toolbar"/>
                        <af:panelCollection id="pc1" styleClass="AFStretchWidth">
                            <f:facet name="menus"/>
                            <f:facet name="toolbar"/>
                            <f:facet name="statusbar"/>
                            <af:table var="row" rowBandingInterval="0" id="t1" value="#{viewScope.BookBean.bookInfo}"
                                      rowSelection="multiple"
                                      inlineStyle="line-Height: 15px;">
                                <af:column sortable="true" headerText="Book SrNo." id="c1">
                                    <af:outputText value="#{row.bookSrNo}" id="ot1"/>
                                </af:column>
                                <af:column sortable="false" headerText="Author Name" id="c2">
                                    <af:outputText value="#{row.bookAuthNm}" id="ot2"/>
                                </af:column>
                                <af:column sortable="true" headerText="Book Description" id="c3" width="300">
                                    <af:outputText value="#{row.bookDesc}" id="ot3"/>
                                </af:column>
                            </af:table>
                        </af:panelCollection>
                    </af:panelBox>
                </af:form>
            </af:document>
        </f:view>
    </jsp:root>
    

  3. The jspx page looks like this.
  4. Now simply run the application.
  5. After the screen that comes up is something like this.
Here is the sample application : TableOnPOJO.rar

ADF : Facebook chat implementation

I had a task in my organisation to implement facebook chat in ADF. After a lot of search on internet and found that chat for facebook can only be inplemented through smacks api. It is available at http://www.igniterealtime.org/downloads/source.jsp .

Download the sample zip application here : Facebookchat.rar


There are three java classes used for the same:



  1. "CustomSASLDigestMD5Mechanism.java" to perform the authentication.
  2. "FBMessageListener.java" to listen to the messages that comes to you from facebook.
  3. "FBConsoleChatApp.java" is the java class that contatins main method i.e. this is the class used for running the program.
GoodLuck.

Thursday, 21 February 2013

ADF: Code to use rowIterator

Hi,
Here is the method to use iterator in ADF Applications.

1)To get iterator object populated with the view rows
RowsetIterator itr=view.createRowsetIterator(null);
*dont use view.getIterator
2)To iterate within the iterator
itr.hasNext();
its.next();

If you have any questions regarding this or in ADF. I will be happy if i can help. :)