Adding custom JavaScript to ADF .jspx page

JavaScript code can be easily implemented into an ADF page. Once implemented, you can control how it is triggered by using a Client Listener.


1. Insert a 'Resource' component into your page structure, then select the type as 'javascript':


2. Add an OutputText component under the Resource component:


3. Paste your JavaScript function directly into the OutputText component. This can be done via Property Inspector, or the Source code

4. Add a ClientListener component into your page structure:


5. The method refers to the JavaScript function you declared under the Resource component, and the Type refers to the type of event that triggers the function:


Behaviour of above scenario: When the above jspx page is opened, it will resize the window to a width of 100 and height of 200.

The way in which the JavaScript is called can be easily manipulated. E.g. The ClientListener component can be added under a CommandButton, and the Type changed to 'click'. In the above scenario, the page would resize to (100,200) when that Button is clicked.

Invalid column index error

After deploying my ADF application and navigating to a certain page, I have been faced with the following error message on screen several times:


The reason for this is due to the following scenario:
  1. Create an Entity Object (EO) from a table.
  2. Create a View Object (VO) from that EO.
  3. Now a new Date column has been added to that table.
  4. The newly added Date column is updated in the EO and VO.
  5. Now from the Data Controls, you drag and drop the Date field onto the page.
  6. Deploy the application and navigate to the page and now you are presented with the above error.
The issue: The above View Object (VO) query is not automatically updated and does not return the column that you are trying to show on the page. In other words, this is the equivalent of a Null pointer exception.

The solution: Manually update the VO query with the newly added Date query, rebuild and then re-deploy.

Convert code snippets into HTML - to insert into Blog Posts

Came across a website whilst writing some of my posts that converts any code snippets into a neat HTML format. The HTML can be easily embedded into blog posts, emails and websites:


http://hilite.me/

Get/Set PageFlowScope values

Following Get/Set Java methods can be used within a Managed Bean:

  • Get PageFlowScope value:
  public Object getPageFlowScopeValue(String name) {
    ADFContext adfCtx = ADFContext.getCurrent();
    Map pageFlowScope = adfCtx.getPageFlowScope();
    Object val = pageFlowScope.get(name); //Name = PageFlowScope value name

    if (val == null) { //Avoid null pointer exception
      return null;
    } else {
      return val;
    }
  }

  • Set PageFlowScope value:
  public Object getPageFlowScopeValue(String name) {
    ADFContext adfCtx = ADFContext.getCurrent();
    Map pageFlowScope = adfCtx.getPageFlowScope();
    Object val = pageFlowScope.get(name); //Name = PageFlowScope value name

    if (val == null) { //Avoid null pointer exception
      return null;
    } else {
      return val;
    }
  }





Get current logged in user

To return the current logged in user in the application, it can be obtained using Java Code, or Expression Language:

  • Java Code - from inside a Managed Bean:
ADFContext adfCtx = ADFContext.getCurrent(); 
SecurityContext secCntx = adfCtx.getSecurityContext(); 
String username1 = secCntx.getUserPrincipal().getName(); 
String username2 = secCntx.getUserName(); 

  • Expression Language - from the Property Inspector or from the Model View Object attribute level:
#{securityContext.userName}