Saturday, October 20, 2012

How to make Default Command working in JSFF Page in AF:Region in JDeveloper 11g

Oracle JDeveloper 11.1.2.1
ADF Faces Rich Component


This post explain how can you set command button to default command in jsff page exposed in af:Region.

While you use jspx pages, af:form component has property DefaultCommand, when set to id of any af:commandButton, invokes the associated action on pressing Enter Key.

However, when you are using page fragment (jsff) page & exposed in region, using this property from parent page would not give right ID of command button bz of surrounding containers.

So, alternative is to use javascript in jsff page in one of the UI component, when the ENTER button is pressed inside this component, a button action is invoked programmatically.

For Example, jsff page has one af:inputText & one af:commandButton to press:

 <af:panelFormLayout id="pfl1" labelWidth="250">  
   
  <af:resource type="javascript">   
     function onEnterKey(inputevent){   
       if(inputevent.getKeyCode() = AdfKeyStroke.ENTER_KEY {   
        var inputTextId = inputevent.getSource();  
   
         //If inputText & Button reside in same container   
         var reportbtn = inputTextId.findComponent('cb2');           
   
         AdfActionEvent.queue(reportbtn);  
   
         inputevent.cancel(); //stop sending event to server  
   
        }  
   
      }  
   
   </af:resource>  
   
   <af:inputText label="Enter Year" id="it1" maximumLength="4" showRequired="true"   
               requiredMessageDetail="Please Enter Year">   
  
        <af:clientListener method="onEnterKey" type="keyUp"/>   
   </af:inputText>  
   
   <af:panelGroupLayout id="pgl2" layout="horizontal" inlineStyle="width:326px;">   
       <af:commandButton text="Show Report" id="cb2" clientComponent="true"/>     
   </af:panelGroupLayout>  
   
 </af:panelFormLayout>  


Please note that af:clientListener tag for inputText & clientComponent=true property of commandButton should present to work with javascript.

Monday, October 15, 2012

Programmatically Showing Popup In JDeveloper 11g

Oracle JDeveloper 11.1.2.1
ADF Rich Components
ADF Business Components

To show af:popup programmatically in adf, you can add script in Managed Bean by ExtendedRenderKitService class.

 import javax.faces.context.FacesContext;  
 import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;  
 import org.apache.myfaces.trinidad.util.Service;  
 public void showPopup (String popupId){  
        FacesContext context = FacesContext.getCurrentInstance();  
        ExtendedRenderKitService extendedRenderKitSrvc =  
        Service.getRenderKitService(context, ExtendedRenderKitService.class);  
        extendedRenderKitSrvc.addScript(context, "AdfPage.PAGE.findComponent('" + popupId + "').show();");  
     }  

Saturday, October 13, 2012

How To Logout From ADF Application Programmatically In JDeveloper 11g ?

Oracle JDeveloper 11.1.1.3
ADF Faces Rich Components
ADF Business Components

As you might know already, from logging out to ADF Application you can set 'Destination' property of af:goLink to your desired page.

 <af:goLink text="Logout" id="gl2"   
     destination="/adfAuthentication?logout=true&amp;end_url=/faces/login.jspx"  
     accessKey="L" shortDesc="Logs-out current user session."/>  

The Logout can also handled programmatically by server side code in managed-bean.
To do so, af:commandLink can be used something like below.

 <af:commandLink text="Logout" id="cl2"   
   action="#{dataentry_bean.onLogout}"  
   immediate="true"  
   shortDesc="Logs-out current user session."  
   accessKey="L"/>  
Setting Immediate=true is optional, and it is for bypassing any validation on page.


The managed bean code -

 import javax.faces.context.ExternalContext;  
 import javax.faces.context.FacesContext;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpSession;  
 import weblogic.servlet.security.ServletAuthentication;  
   
   public String onLogout(){  
     FacesContext fctx = FacesContext.getCurrentInstance();  
     ExternalContext ectx = fctx.getExternalContext();  
     String url = ectx.getRequestContextPath() + "/adfAuthentication?logout=true&end_url=/faces/login.jspx";  
       
     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(Exception e){  
       e.printStackTrace();  
     }  
     fctx.responseComplete();  
       
     return null;  
   }