Showing posts with label adf. Show all posts
Showing posts with label adf. Show all posts

Wednesday, June 18, 2014

What is save point restore and how to configure it and use it in Oracle ADF?

Save point restore is a mechanism to save a particular state of the current ADF application transaction state and return to it after a certain amount of time (not more than 24hrs)

We can use the save point restore facility in the ADF taskflows to return to that particular state. If we use this, the application will store the following information temporarily to the database and retrieves it when we require.

The information stored at the save point is
  1. Current ADF model transaction state of the application
  2. Memory states of the ADF Controller specific scopes - Page flow scope and View scope
  3. ADF controller navigation state, all the taskflow calls to come to this state
  4. UI state of the current page like the tabs opened, rows of the table selected, choices selected in the Boolean checkbox 
By default, the saved information is active in the database for 24 hours and is deactivated after that.

Steps to configure and use the save point restore

Step1: Indicate the database connection that will be used to save the state in the adf-config.xml file which can be found in application resources -> Descriptors -> ADF META-INF -> adf-config.xml

Select the data source of the database where the framework can store the application state as below

 


Clicking the check box enable implicit savepoints will save the application state automatically when the taskflow is marked as critical

Step2:

Decide the step in the taskflow where you want to save the state and invoke the controller method just before that to save the state as below.



The properties of the method to be executed are as below


The managed bean property configured in the return value of the method is a string and looks as below









Step3

Drag and drop the save point restore activity on to the current taskflow as shown in the tasflow. The properties of the activity are as below










Step4

Configure the command button/command link on clicking which the last change will be undone. Point the action property of the button to invoke the save point Restore activity

Tuesday, June 17, 2014

Change the webcenter portal default preferences based on a condition?

By default when the Oracle webcenter portal application is created, it comes up with the default navigation modal, default navigation registry, default skin etc...


If we would like to change then for example based on the security context of the user logged in, we can do so. All the default preferences are stored in adf-config.xml as below

<portal:preferences>
  <portal:preference id="oracle.webcenter.portalapp.navigation.model"
                     desc="Default Navigation Model"
                     value="/oracle/webcenter/portalapp/navigations/default-navigation-model.xml"
                     resourceType="navigation" display="true"/>
  <portal:preference id="oracle.webcenter.portalapp.resourcecatalog"
                     desc="Default Resource Catalog"
                     value="/oracle/webcenter/portalapp/catalogs/default-catalog.xml"
                     resourceType="ResourceCatalog" display="true"/>
  <portal:preference id="oracle.webcenter.portalapp.pagetemplate.pageTemplate"
                     desc="SPR Page Template"
                     value="/oracle/webcenter/portalapp/pagetemplates/MyAppTemplate.jspx"
                     resourceType="Template" display="true"/>
  <portal:preference id="oracle.webcenter.portalapp.navigation.renderer"
                     desc="Default Navigation Renderer"
                     value="/oracle/webcenter/portalapp/pages/navigation-renderer.jspx"
                     display="false"/>
  <portal:preference id="oracle.webcenter.portalapp.skin"
                     desc="Default Portal Skin" value="portal"
                     resourceType="Skin" display="true"/>
  <portal:preference id="oracle.webcenter.portalapp.sitemap"
                     desc="Default Sitemap EL"
                     value="#{navigationContext.defaultNavigationModel.defaultSiteMap}"
                     resourceType="Sitemap" display="true"/>
  <portal:preference id="oracle.webcenter.portalapp.baseresourceurl"
                     desc="Default Base Resource URL EL"
                     value="#{request.scheme}://#{request.serverName}:#{request.serverPort}#{request.contextPath}"
                     resourceType="BaseResourceURL" display="true"/>
</portal:preferences>


We can change/configure them based on an EL expression as shown below

<portal:preference id="oracle.webcenter.portalapp.navigation.model"
    desc="Default Navigation Model" resourceType="navigation" display="true"
    value="#{securityContext.authenticated ? /oracle/webcenter/portalapp/navigations/default-navigation-model.xml : /oracle/webcenter/portalapp/navigations/custom-navigation-model.xml"/>
   


Preserve runtime customizations of webcenter portal application?

Scenario:

Let is say we have developed a webcenter application using JDeveloper and made some runtime customizations from the webcenter portal administration console. Running the application again from the Jdeveloper removes all the customizations made.


Background

All the runtime customizations made are stored in a component called MDS but not in the physical folder location of JDeveloper application. And by default on running the portal application, all the runtime customizations are deleted.

Solution

To avoid this we have to override this default behavior from the portal application properties settings by clicking the preserve customizations across application runs as shown below.



Monday, June 16, 2014

How to customize the administration console URL in wecenter portal

By default, we can access the webcenter portal administration console from the following URL
http://www.app-server:port/applicaiton-context_root/admin.

We can customize it by making the following changes to the web.xml

  <servlet>
    <servlet-name>PortalAdminServlet</servlet-name>
    <servlet-class>oracle.webcenter.portalwebapp.servlet.PortalAdminServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>PortalAdminServlet</servlet-name>
    <url-pattern>/desired-url</url-pattern>
  </servlet-mapping>

Thursday, June 12, 2014

Introudction to JDeveloper 12c and effective ways to use it?

Apply a template at runtime in Oracle webcenter portal

We might need to change the application template at runtime from the Oracle Webcenter portal administration console. This can be done as shown below

Step1: 
  1. Make sure that template is available and not hidden
  2. If not available, select a particular template and click the edit button and select "Show"  















Step2:

Choose and apply the template from the configuration tab as shown below


Friday, June 6, 2014

Get the ResourceBundle handle based on the current Locale in ADF

import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import javax.faces.component.UIViewRoot;
import java.util.Locale;

private static ResourceBundle getBundle() {
    FacesContext ctx = getFacesContext();
    UIViewRoot uiRoot = ctx.getViewRoot();
    Locale locale = uiRoot.getLocale();
    ClassLoader ldr = Thread.currentThread().getContextClassLoader();
    return ResourceBundle.getBundle(ctx.getApplication().getMessageBundle(), locale, ldr);
}

Find if a ShowDetailItem is collapsed or expanded in managed bean?

Sometimes wither in the Panel Tabbed Layout or Panel Accordion, we would like to find if the show detail item is collapsed or expanded. This can be done as below

import oracle.adf.view.rich.component.rich.layout.RichShowDetailItem;

public void onClickSDITwo(DisclosureEvent disclosureEvent) {
    RichShowDetailItem item = (RichShowDetailItem)disclosureEvent.getSource();

    if (disclosureEvent.isExpanded() == true) {
        // If the show detail item is expanded then show all its children
        item.setDisclosed(true);
    }
    else if (disclosureEvent.isExpanded() == false) {
        // If the show detail item is collapsed then hide all its children
        item.setDisclosed(false);
    }
}

How to avoid java.io.NotSerializableException in Oracle ADF?

There are a few reasons for this error to appear in the logs.
  1. The managed bean class is not implementing Serializable and the bean is in scope greater than viewScope.
  2. The other reason could be that you have UI Component bindings in the serialized bean with scope greater than viewScope.
To avoid these error messages, you need to keep following things in mind while developing managed beans.
  1. Do not bind UI Components in managed beans with scope more than viewScope.
  2. If you have to use UI Component bindings then use backing bean to bind the UI Components and reference the pageFlowScope bean inside backing bean to process the important data.
Also by default the JDeveloper will not display these messages on the integrated server. To enable these message on the integrated server, run the server with following JVM parameter


-Dorg.apache.myfaces.trinidad.CHECK_STATE_SERIALIZATION=all

Monday, June 2, 2014

Create Oracle ADF business components based on Microsft SQL server

Inorder to do that, we need to connect to the Microsft SQL Server as described below

Platform - Win 7 x86 Enterprise
MS SQL Server 2008 Database Engine
JDeveloper 11.1.1.3

Oracle JDeveloper 11g uses JDBC 4.0 to connect with RDBMS since JDK1.6 supports JDBC4.0 & 
JDeveloper uses JDK 1.6 to compile all its classes. ojdbc6.jar classes to support basic 
functionality for the Thin and OCI drivers when using JDK 1.6 (JSE6) with Oracle database. 
Additional jar files are required when you use some features. See Oracle JDBC FAQ .

Well, that was of Oracle Database. MS SQL Server provides SQLJDBC4.jar class library, 
which provides support for JDBC 4.0. If you dont have this jar files, you won't be able to 
connect to MSSql server database. You can download from Microsoft.

1. Download sqljdbc4.jar from microsoft & save in filesystem.

2. Open JDeveloper & register the library file from Tool > Manage Libraries.

3. Click 'New' button by keep selecting 'User' Node.

4. In the 'Create Library' dialog click 'Add Entry' & locate your sqljdbc4.jar file & click 'Select' .

5. Optionally, you can check 'Deployed by default'.


managelibrary

6. Click OK.

7. Now, you are ready to establish connection to MSSQL Server.

8. Make sure your sqlserver engine is running & the account you are going to use for connect, is not
    locked.

9. From Database Navigator, create a new connection.

10.Next Screenshots are self explanatory except for 'Library' field where click 'Browse' & locate the jar file
     from 'Select Library' dialog.



selectLibrary

ConnectionDialog

































11. Click Test Connection to test the connection.
Reference: http://adfblogspot.blogspot.com/2012/06/connecting-ms-sql-server-database-from.html

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;

Tuesday, April 29, 2014

How to use route activity in ADF taskflows?

If we would like to route the flow inside a taskflow based on the outcome of an expression, then we should use the Route activity.

Step1: Configure the Route activity as shown below in the taskflow
























In the above taskflow we observe that the router1 activity is the default activity. But where should the navigation go in the next step is determined by the expressions configured in the route activity

Step2: Configure the outcomes based on the outcome of an EL expression as shown below.
















Note:
  1. The default outcome is mandatory for the route activity.
  2. If the router outcome matches a from-outcome on a control flow case, control passes to the activity that the control flow case points to.
  3. If none of the cases for the router activity evaluates to true, or if no cases are specified, the outcome specified in the router default outcome field (if any) is used.

Easy way to store a value in a memory scope variable on button, commandlink click in ADF.

We can use the af:setPropertyListener as mentioned below to achieve the same.

<af:commandButton id="cb3" blocking="true">
    <af:setPropertyListener from="#{row.employeeId}" to="#{pageFlowScope.address}"
                                           type="action"/>
</af:commandButton>

The setPropertyListener tag provides a declarative syntax for assigning values when an event fires. The setPropertyListener implements the listener interface for a variety of events, to indicate which event type it should listen for set the 'type' attribute.