Wednesday, March 27, 2013

Closing Browser When User Clicked On Logout


When user clicked on Logout button/link in JSF page, we can call Javascript to close browser window.

This can be achieved through 2 different ways.
1. We can directly call JavaScript using clientlistener for command button. This method more faster.
2. We can call Java method to execute Javascript using RenderKitService API. This method allows to perform any logic on server side during logout.

Following Sample Code Snippets will help you to do it.


JSF Page Source:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:resource type="javascript">
        function closeWindow(evt) {
            window.close();
        }
      </af:resource>
      <af:form id="f1">
        <af:panelStretchLayout id="psl1">
          <f:facet name="center">
            <!-- id="af_one_column_stretched"   -->
            <af:panelGroupLayout layout="vertical"
                                 xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
                                 id="pgl1">
              <af:outputText value="Hello There! This is a Sample Page to test browser close on clicking Logout button"
                             id="ot1"
                             inlineStyle="font-weight:bolder; font-size:small;"/>
              <af:spacer id="s1" height="30" width="20"/>
              <af:outputText value="Clicking on --Logout1-- Button will call Java bean method to execute Javascript uisng Renderkit"
                             id="ot2" inlineStyle="color:Green;"/>
              <af:commandButton text="Logout1" id="cb1"
                                action="#{pageFlowScope.signOutBean.logOutApp}"
                                partialSubmit="true"/>
              <af:spacer id="s2" height="20" width="20"/>
              <af:outputText value="Clicking on --Logout2-- Button will call Javascript written on page"
                             id="ot3" inlineStyle="color:Maroon;"/>
              <af:commandButton text="Logout2" id="cb2" immediate="true">
                <af:clientListener method="closeWindow" type="action"/>
              </af:commandButton>
            </af:panelGroupLayout>
          </f:facet>
        </af:panelStretchLayout>
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

Managed Bean Source:

import java.io.IOException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
import weblogic.servlet.security.ServletAuthentication;

public class signOut {
    public signOut() {
        super();
    }

    public String logOutApp() {
        // Add event code here...
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext ectx = facesContext.getExternalContext();
        //String url = ectx.getRequestContextPath() + "/adfAuthentication?logout=true&end_url=/faces/logout.jspx";

        ExtendedRenderKitService service = Service.getRenderKitService(facesContext,ExtendedRenderKitService.class);
        service.addScript(facesContext, "window.close();");  

        HttpSession session = (HttpSession)ectx.getSession(false);
        session.invalidate();
        
        HttpServletRequest request = (HttpServletRequest)ectx.getRequest();
        ServletAuthentication.logout(request);
        ServletAuthentication.invalidateAll(request);
        ServletAuthentication.killCookie(request);

//        try {
//           ectx.redirect(url);
//        } catch (IOException e) {
//           e.printStackTrace();
//        }
//        facesContext.responseComplete();
        return null;
    }

}

Monday, March 25, 2013

Create BPM Process using Composer

Applicable to BPM Suite 11g (11.1.1.6.0):

Instead of using BPM Studio (Jdeveloper), we can use BPM Composer to create BPM process on fly. Following tutorial gives steps to create simple BPM process using BPM Composer.
  • Login to BPM Composer http://localhost:8001/bpm/composer

  • BPM Composer page will be displayed as shown below. Existing projects also displayed under BPM Projects. Click on New Project.

  • Enter Project Details (Name, Description, Template). Select Workflow if needed. Restrict project access. Click Finish.



  • Click on New process under Project Home tab and provide Process Name.

  • Click on Created BPM Process.

  • Process Flow window appears as shown below. Right Click on Start activity and select Implement. Add required arguments as Input Parameters. For Ex: FirstName(String) & LastName(String). Click on Apply Changes and Save.

  • Again Right Click on Start activity and select Data Association. Add required data objects to hold input data. For Ex: add FirstName(String) & LastName(String) as shown below.





  • Drag and drop created data objects to create mapping between input parameters and process data objects. Click Apply.


  • Go back to Process tab . Right click on End activity and select Implement. Add Output arguments. For Ex: FullName(String). And select process as Synchronous and select Reply to Start activity. Click Apply Changes.
  • Again Right click on End activity and select Data Association. Click on Express function and Add Simple expression. For Ex: FirstName + " " + LastName. Click on Apply.


  • Save the project and click on Validate. Check Validation tab.


  • Click On Save and Release. Click on Main Menu and select Deployment --> Deploy project. Enter credentials and project revision etc. Click on Deploy. A confirmation window will be appeared once deployment is completed.



Saturday, March 23, 2013

Apply Default View Criteria from AM

In order to trigger view criteria automatically, please follow below steps:

  • Create a View Object(For Ex: Departments) and Go to Query section add a View Criteria.
  • Create a View Object(Employees) and Go to View Accessors section add a Departments View Object as a  View Accessor.
  • Select Accessor link and click on Edit.
  • Shuttle required default View Criteria to right box and save it.

After performing above steps, the View Criteria we want to trigger automatically will be invoked each time when View Object will be accessed.


Wednesday, March 20, 2013

Code Auditing in Jdev



Code auditing is analysis of code for adherence to programming standards. It results in better code that is easier to maintain. Oracle JDeveloper 11g comes with an extensive set of predefined rules for auditing Java code. In addition you can create your own auditing rules and add them to JDeveloper. JDeveloper let you group Auditing rules into profiles. This provides an easy mechanism to customize the rules used to validate your code.

Some examples of the areas that JDeveloper's audit rules can help enforce include:
  • Proper usage of common Java APIs.
  • Proper declaration of classes, methods, and fields.
  • Completeness and correctness of Javadoc comments.
  • Adherence to standard naming conventions
  • Eliminating unused declarations.
Auditing code should be part of every project's build process, making code quality assurance an integral part of the project.
In order to view the default Audit profiles, Open JDeveloper and go to Tools --> Preferences --> Audit --> Profiles you will see a list of the profiles defined by default.
To run these Audit rules against your code, go to Build --> click on Audit <Project Name> to run Audit profile.

Ref: https://blogs.oracle.com/jdevextensions/entry/running_an_audit_from_the







Friday, March 15, 2013

Error While adding Trinidad HTML Components to JSF Page


When we try to use trinidad html components inside JSF page in Jdeveloper, we will get error message that no grammar available for namespace http://myfaces.apache.org/trinidad/html"
Follow these steps to get rid of this error message
  1. Right Click into the component palette and choose “edit tag libraries” from the context menu
  2. Shuffle “Trinidad HTML Components 1.2” to the list of selected libraries and click Ok
  3. Now try to add one of components from component palette à Trinidad HTMl. The message will disappear.




Enabling Multi Selection in af:query component


In some cases, we might need to allow user to select multiple values while searching data using search functionality. To accomplish this requisite, ADF framework provides a declarative approach. I have given a sample example using HR schema available with XE. Follow the steps mentioned below.

  1.  Create Employees & Departments View Objects
  2. Go to Employees VO attributes section and add LOV to DepartmentId attribute based on values from Departments VO
  3. Go to Employees VO query section and add view criteria For ex ‘EmployeesVOCriteria’
  4. Inside the view Criteria, add DepartmentId attribute. Move to UI Hints tab, under Criteria Item UI Hints section, select DepartmentId, and check ‘Support Multiple Value Selection’. Save.
  5. Go to UI project, add a page, and drag EmployeesVOCriteria as Query Panel into page.
  6. Run the page
k