Nov 2, 2012

How to set default values for Entity object attributes.

In this demo I am going to set default value of  hire date of  employees to today's date

There are 3 ways to set default values:-
1.) In the overridden create() method of the Entity object  class:-
       Generate EmployeesImpl.java class of  EmployeesEO Entity Object.
       Add the following code to create() immediately after the call to super.create() .
            this.setHireDate((Date)Date.getCurrentDate());



2.) Declaratively using a Groovy expression:-
  • Open the Employees Entity object and go to the Attributes page. 
  • Select the attribute HireDate.
  • Select the Details tab.
  • In the Default Value section, select Expression and enter the following Groovy
    expression: adf.currentDate

       
3.)In the attribute getter method:-
  • Go to getHireDate() method in the EmployeesImpl.java class.
  • Replace the existing code in getHireDate() with the following:

               Date hireDate = (Date)getAttributeInternal(HIREDATE);
               // check for null and return today's date if needed
               return (hireDate == null) ? (Date)Date.getCurrentDate() :
               hireDate;


Oct 16, 2012

ADF Switcher component


The switcher component dynamically decides which facet component should be rendered. It has two properties. The switcher will render the facet matching "facetName"; however, if no such facet exists (or "facetName" is null), and "defaultFacet" has been set, then that facet will be used instead.

Steps:

1.Create VOs based on different tables in the Model Layer:

 

 

2. In View Controller, create a View Page .Drag a Panel Group Layout from the Component Palette onto the page.


3. Drag the Switcher component from the Component Palette into the Panel Group layout.



4.Right Click the af:Switcher component > Insert Inside af:Switcher > Facet




5.Provide a Name for the Facet. Create 2 Facets and provide corresponding names for both.




6.Drag the 'Dept' VO from the Data Controls onto the Facet with name 'Query1' and create a table using the VO.



7.Repeat the Step for 'Emp' VO and create the table in 'Query2' facet. The structure would look as the figure below :




8. Select the Switcher Component and change the DefaultFacet property to 'Query1'



9.In the FacetName property of the Switcher, write #{requestScope.table}



10. Drag a 'Choice' component from the component palette before the Panel group layout .
Provide 2 static values (Facet Names that have been created earlier are taken as Item Values)in the create list tab as shown in the following figure.





11. Change the AutoSubmit property of the Select One Choice to 'true' .

12. Also Provide PartialTrigger property of the Panel Group Layout with the id of the Select One Choice component.
13. Run the Page.