Tuesday, March 26, 2013

Get the currently selected row in Application Module (AM) in ADF

If there is any table component in the ADF UI , and you want to get the currently selected row in the Application module use the following code snippet

Let the VO name be StockDetailsVO

Steps
1. Get the VO instance
2. Get the currently selected row
3. Get the data from currently selected row

    public void addStocksToPortfolio() {
        // get the VO instance
        StockDetailsVOVOImpl vo = getStockDetailsVO();

        //Get the currently selected row, typecast it to VORowImpl Class type
        StockDetailsVORowImpl currentRow = (StockDetailsVORowImpl)getStockDetailsVO().getCurrentRow();       

         //We get the data as below
        int stockID = currentRow.getStockid();
        String stockName = currentRow.getTimeadded();
}

Sunday, March 24, 2013

Iterate through the vo.executeQuery() results in ADF

Some times we execute a ViewObject (VO) in the ApplicationModule (AM). We want to iterate through the results returned.

The following sample code snippet will do the same

public String autoComplete(){
       StockDetailsVOImpl vo = getStockDetailsVO();   
        vo.executeQuery();
        while (vo.hasNext()) {
            //Type case the returned row to the VORowImpl type
            StockDetailsVORowImpl newRow = (StockDetailsVORowImpl) vo.next();
          
            //use the getter and setter methods of RowImpl Class to get the respective column details
            newRow.getCloumName());
            }
        }

Saturday, March 23, 2013

Execute a ViewObject (VO) query in ApplicationModule (AM)

For example let
  1.  VO name be StockDetailsVO
  2. AM name be StockMarketAM

 If the Java class for the VO is not generated
  • Go to the Java section of the StockDetailsVO and generate the StockDetailsVOImpl.java
  • If you have the Bind Variables, then click the check box Include bind variable accessors
 If the Java class for the AM is not generated
  •  Go to the Java section of the AM and generate the StockMarketAMImpl.java
Use the following code snippet

    public void executeViewObject() {
       StockDetailsVOImpl vo = getStockDetailsVO();
       vo.executeQuery();
   }

If you want to set some Bind Variable value before executing the VO, use the following code

    public void executeViewObject(int portfolioID) {
       StockDetailsVOImpl vo = getStockDetailsVO();
       vo.setBindPortfolioID(portfolioID);
       vo.executeQuery();
    }

Thursday, March 21, 2013

Type ahead / AutoSuggestion




Usecase :  Display list of values automatically while user types / Auto Suggestion

Implementation




Drag autoSuggestBehavior component and binds to Backing bean method





Backing Bean Method :