Wednesday, May 21, 2014

How to create a Grid layout view in Oracle ADF?

Sample Jsff looks as below

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:trh="http://myfaces.apache.org/trinidad/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich" version="2.1">
  <trh:tableLayout id="tl2" cellSpacing="7">
    <trh:rowLayout id="rl12">
      <trh:cellFormat id="cf13" width="30%">
        <af:outputText value="Header1" id="ot1"/>
      </trh:cellFormat>
      <trh:cellFormat id="cf2" width="70%">
        <af:outputText value="Header2" id="ot3"/>
      </trh:cellFormat>
    </trh:rowLayout>
    <trh:rowLayout id="rl1">
      <trh:cellFormat id="cf6" width="30%">
        <af:outputText value="Content1" id="ot7"/>
      </trh:cellFormat>
      <trh:cellFormat id="cf9" width="70%">
        <af:outputText value="Content2" id="ot6"/>
      </trh:cellFormat>
    </trh:rowLayout>
  </trh:tableLayout>
</jsp:root>


The look and feel as below


Wednesday, May 14, 2014

How to insert the row at a given location in the table in Oracle ADF?

import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;
import oracle.jbo.NavigatableRowIterator;
import oracle.jbo.Row;
import oracle.jbo.uicli.binding.JUCtrlHierBinding;
import oracle.adf.model.binding.DCIteratorBinding;

public String createEmployeeAtBottom() {
        BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding hierBinding = (JUCtrlHierBinding)bc.get("EmployeesView");
        DCIteratorBinding dciter = hierBinding.getDCIteratorBinding();
        NavigatableRowIterator rowIter = dciter.getNavigatableRowIterator();
        Row newRow = rowIter.createRow();
        newRow.setNewRowState(Row.STATUS_INITIALIZED);

        Row lastRow = rowIter.last();
        int lastRowIndex = rowIter.getRangeIndexOf(lastRow);

        //Modify this step as per requirement and as described below
        rowIter.insertRowAtRangeIndex(lastRowIndex + 1, newRow);
        dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
        return null;
    }

Insert the row at the beginning of the table
rowIter.insertRowAtRangeIndex(0, newRow);

Create a new row before the currently selected row
rowIter.insertRow(newRow);

Create a new row after the currently selected row
Row currentRow = rowIter.getCurrentRow();
int currentRowIndex = rowIter.getRangeIndexOf(currentRow);
rowIter.insertRowAtRangeIndex(currentRowIndex+1, newRow);


Display a Severe/Error/Warning/Info messages in ADF

To display Fatal Error Message
addFacesMessage(FacesMessage.SEVERITY_FATAL, "User Message");

To display Error Message
addFacesMessage(FacesMessage.SEVERITY_ERROR, "User Message"");

To display Warning Message
addFacesMessage(FacesMessage.SEVERITY_WARN, "User Message"");

To display Info Message
addFacesMessage(FacesMessage.SEVERITY_INFO, "User Message"");

// The method that displays the message.
public static void addFacesMessage(FacesMessage.Severity severity, String message) {
    FacesMessage fm = new FacesMessage(severity, message, null);
    FacesContext.getCurrentInstance().addMessage(null, fm);
}

Most Used ADF security Context methods

Check if the current user authenticated?
ADFContext.getCurrent().getSecurityContext().isAuthenticated();
Return Boolean;

Get the currently Logged in user.
ADFContext.getCurrent().getSecurityContext().getUserName()
Return String;

Check if the user is present in a given Role
ADFContext.getCurrent().getSecurityContext().isUserInRole("Role-Name")
Return Boolean

Get the Array of roles of current user
ADFContext.getCurrent().getSecurityContext().getUserRoles()
Return String[]

Check if Authentication is enabled for the application
ADFContext.getCurrent().getSecurityContext().isAuthenticationEnabled()
Return Boolean

Check if Authorization is enabled for the application
ADFContext.getCurrent().getSecurityContext().isAuthorizationEnabled()
Return Boolean  

How to create the View Criteria Programmatically in ADF?

public void searchEmployee(Number employeeId, String email) {
    EmployeesVOImpl vo = getEmployeesVO1();
    ViewCriteria vc = vo.createViewCriteria();
    ViewCriteriaRow vcRow = vc.createViewCriteriaRow();

    vcRow.setAttribute("EmployeeId", employeeId);
    vc.addRow(vcRow);

    vcRow.setAttribute("Email", email);
    vc.addRow(vcRow);

    vo.applyViewCriteria(vc);
    vo.executeQuery();
}

Tuesday, May 13, 2014

EL expression to get the url upto Context Root in ADF?

Sometimes we might need the URL till the Context Root in ADF. The following is the expression
${pageContext.request.contextPath}

Example Usage:

<div class="displayLogo" style="display: none">
   <img src="${pageContext.request.contextPath}/img/logo.png"/>
</div>

Tuesday, May 6, 2014

How to hide or make a page visible in Oracle Wecenter Portal application?

On creating the webcenter portal application from the JDeveloper, we get a default-navigation-model.xml where the top level hierarchy and the navigation of pages in the portal is defined.

In that navigation model we can specify to make a page to be either visible or not based on a EL Expression as shown below


Monday, May 5, 2014

get the current user in PL/SQL oracle?

SELECT lower(sys_context('USERENV','SESSION_USER'))
  || '@'   || lower(sys_context('USERENV','DB_NAME'))
FROM dual;