10 March, 2019

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope.
There are five scopes in ADF (Application, Request, Session, View and PageFlow).
The below code snippest explains how to get value of each variable scope.

        AdfFacesContext adfCtx = AdfFacesContext.getCurrentInstance();
                
        //Page Flow Scope
        Map pageFlowMap  = adfCtx.getPageFlowScope();
        Object pageFLowVariable = pageFlowMap.get("VARIABLE_NAME");
        
        //View Scope
        Map viewMap  = adfCtx.getViewScope();
        Object viewVariable = viewMap.get("VARIABLE_NAME");
        
        //Session Scope
        HttpServletRequest request =
            (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        HttpSession session = request.getSession(false);
        Object sessionVariable = session.getAttribute("VARIABLE_NAME");
        
        //Request Scope
        Object requestVariable = request.getAttribute("VARIABLE_NAME");
        
        //Application Scope
        Map applicationMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
        Object applicationVariable = applicationMap.get("VARIABLE_NAME");




Thanks

09 January, 2019

How to Pass Parameters to ActionListener in ADF

In some cases, it is required to pass a value to ActionListener of ADF Button.

The method that can be invoked by actionListeners has only one parameter of type ActionEvent. 
So I will explain how to pass parameter to that bean method however it contains only one paramater ActionEvent in method signature.

I added button to my page as below



The default signature of ActionLister is 




The workaround I used is adding an attribute tag from the JSF.Core inside the ADF Button So the code in the jsp page looks like this



Note "MyAttrName" is the name of paramater and "MyAttrValue" is the value of paramater.
You can bind  "MyAttrValue" to get any value from page definition.
Now I will write the followign code to get paramatervalue from bean

 
The variable "attrValue" holds the value of paramaters which is "MyAttrValue" in this example.

Thanks
Mahmoud Elsayed

28 November, 2017

OAF :Formatting DateTime Fields

Use the following code to format DateTime feilds in OAF

OAWebBean departureDateBean = webBean.findChildRecursive("DepartureDate");

OANLSServices nls = pageContext.getOANLSServices();
oracle.cabo.ui.validate.Formatter formatter =
    new OADateValidater(nls.getUserJavaDateFormat() + " HH:mm",
                        nls.getUserRRRRJavaDateFormat() + " HH:mm");
                       
departureDateBean.setAttributeValue(ON_SUBMIT_VALIDATER_ATTR, formatter);


Thanks

26 November, 2017

OAF : Bundled Exceptions

Bundled exceptions let you accumulate "peer" exceptions while proceeding with validation, and then display them as a set when you are done. These peer exceptions are grouped in a container exception called a bundled exception.

To creat a bundled exception, you first must create a list to which you add exceptions as you encounter them:

ArryList peerExceptions = new ArrayList();
peerExceptions.add(new OAException(....));
peerExceptions.add(new OAException(....));

//Raise Exceptions
OAException.raiseBundledOAException(peerExceptions );

Thanks

21 November, 2017

OAF : Programmatically Add a Parameterized Pop-up

To programmatically add a parameterized pop-up to a component , add the following code in processRequest method

Step 1: Create an OAPopupBean 

 OAPopupBean popupBean1=(OAPopupBean)createWebBean(pageContext,POPUP_BEAN,null,"myPopup1");
popupBean1.setID("myPopup1");
popupBean1.setUINodeName("myPopup1");
popupBean1.setRegion("/oracle/apps/per/xyz/webui/PopupRN");
popupBean1.setHeight("130");
popupBean1.setWidth("320");
popupBean1.setTitle("Popup Title");
popupBean1.setParameters("personId={@PersonId}");
popupBean1.setType(PARAMETERIZED_POPUP);


Step 1: Add popup to item which you want to enable the pop-up, for example "EmpDtlBtn" button

OAButtonBean empDtlBtnBean = (OAButtonBean)webBean.findChildRecursive("EmpDtlBtn");
empDtlBtnBean.setPopupEnabled(true);
empDtlBtnBean.setPopupRenderEvent("onClick");
empDtlBtnBean.setPopupID("myPopup1");

webBean.addIndexedChild(popupBean1);


Thanks

24 September, 2017

Casting Data Type in Oracle Database

CAST function 
The CAST function converts a value from one data type to another data type.

Syntax
CAST ( [ Expression | NULL | ? ] AS Datatype)

Note : CAST conversions among SQL-92 data types.
The flowing are SQL-92 data types
  1. BOOLEAN
  2. SMALLINT
  3. INTEGER
  4. BIGINT
  5. DECIMAL
  6. REAL
  7. DOUBLE
  8. FLOAT
  9. CHAR
  10. VARCHAR
  11. LONG VARCHAR
  12. CHAR
  13. VARCHAR
  14. LONG VARCHAR
  15. CLOB
  16. BLOB
  17. DATE
  18. TIME
  19. TIMESTAMP
  20. XML
Examples
SELECT CAST (SYSDATE AS VARCHAR2 (12)) DATE_TO_VARCHAR FROM DUAL;
SELECT CAST ('12' AS INTEGER)  STRING_TO_NUMBERIC FROM DUAL;
SELECT CAST (NULL AS VARCHAR2 (2)) NULL_TO_STRING FROM DUAL;

As CAST only convert among SQL-92 data types, we can not use for example RAW data type.
But there are some packages casts to RAW like utl_raw.cast_to_raw

SELECT UTL_RAW.CAST_TO_RAW('Mahmoud') FROM DUAL;
output is : "4D61686D6F7564"

18 September, 2017

ADF : Send Parameter to actionListener method inside Bean

actionListener method method can be invoked by Adf Button , Link and Image.
actionListeners methods have only one parameter of type javax.faces.event.ActionEvent.

if requirement is to send some parameter to that bean method who’s signature is something like
public void myActionListener(ActionEvent actionEvent)

The solution to achieve this requirement is putting an attribute tag from the JSF.Core inside the commandButton (or whatever actionable component you are using). So the code in the jsp page looks like this:



Now i can get the value in the bean method by using below code

public void myActionListener(ActionEvent actionEvent) {
  // Add event code here...
  String paramValue = (String)actionEvent.getComponent().getAttributes().get("paramName");
  System.out.println("paramValue = " + paramValue);
}


ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...