How to reuse a View Object (VO) for different search criteria in multiple pages in ADF

Scenario: We need to display data in multiple JSF pages based on the single View Object (VO) with different WHERE condition for each of the JSF page.

For this to achieve usually we will create one View Object (with WHERE clause specific to the data that need to be displayed in this JSF) per one JSF page. Finally we will  be creating multiple View Objects (with different WHERE clause) , which is not a best practice to follow.

Resolution: You need to create a method in the Managed Bean of each JSF page and access the View Object (VO) Iterator then create a View Object, then create View Criteria by setting the WHERE condition and execute the View Object.

Sample Code is below –

   public String searchBnftWtngPeriodSet() {
        //Get the bindings    
          BindingContainer bindings = getBindings();
 
        //Refer to your View Object Iterator that was added into your JSPX page
          DCIteratorBinding it = (DCIteratorBinding)bindings.get(“SummaryVO1Iterator“);
 
       //Access the View Object
          ViewObject viewObject = it.getViewObject();
 
      //Create the View Criteria
          ViewCriteria viewCriteria = viewObject.createViewCriteria();
     
      //Get the viewCriteriaRow for the View Criteria  
            ViewCriteriaRow viewCriteriaRow = viewCriteria.createViewCriteriaRow();
 
      //Add the AND logical operator to the viewCriteriaRow
            viewCriteriaRow.setConjunction(ViewCriteriaRow.VCROW_CONJ_AND);
 
     //Set the search criteria (where condition) to the viewCriteriaRow
    // ‘WaitingPeriodId’ is the attribute and ‘5429’ is the value we are  
   // adding in the WHERE condition
            viewCriteriaRow.setAttribute(“WaitingPeriodId“,5429);
 
      //Add the viewCriteriaRow to the View Criteria   
            viewCriteria.add(viewCriteriaRow);           
 
      //Add the viewCriteria to the View Object (VO)
          viewObject.applyViewCriteria(viewCriteria);
 
     //Execute the viewCriteria
          viewObject.executeQuery();
          return null;
    }

By following the above approach, we no need to create multiple View Objects  (VO) and we can access only single View Object (VO) and can add multiple WHERE clause condition in the Managed Bean which is independent of other JSF pages.

Advertisements
This entry was posted in ADF (Application Development Framework) and tagged , , , , , , , . Bookmark the permalink.

9 Responses to How to reuse a View Object (VO) for different search criteria in multiple pages in ADF

  1. ammar says:

    can you use this technique while utilizing bind variables techiques

  2. Lalit says:

    Great… Thanks..Udaya.

  3. Gerardo BaezOropeza says:

    I have one problem in the line: viewCriteriaRow.setAttribute(“WaitingPeriodId“, “5429“);, I see this error: “oracle.jbo.NoDefException: JBO-25058: Attribute type WaitingPeriodId description SummaryVO1 is not found”. I have the parameters configurations necessary, Can You Help me? thanks.

  4. Bo Hyun Kim says:

    Hi,

    what if it is one view object over multiple uses in ONE jspx page? I need to have two tree tables based on this VO:
    1. tree table straight from data controls
    2. tree table that gets generated after a search query

    Once I have executed a query on the search-tree table, it locks in that view criteria and messes up the regular tree table by only showing the query result.

    Can I resolve it without having to create another VO for the second use?

    Thanks,
    Bohyun

  5. Oh my goodness! Awesome article dude! Many thanks,
    However I am going through issues with your RSS. I don’t understand why I cannot subscribe to it. Is there anybody else having similar RSS issues? Anyone who knows the solution will you kindly respond? Thanks!!

  6. If you would like to get much from this paragraph
    then you have to apply these strategies to your won weblog.

  7. Carrol says:

    I pay a visit every day a few web pages and inforrmation sites to read articles
    or reviews, however this blo offers quality based content.

  8. Jerson Viveros says:

    What happen if I need to change not only WHERE but FROM too? and by the other hand, if it is necesary to create another VO, how can I use the same view.

    For instance:

    I have view a.jspx with a table of data.

    With condition 1, I execute the VO1, to fill the table.
    With condition 2, I execute the VO2, to fill the same table.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s