Flipkart Search

Thursday, 26 December 2013

Normal Pop up implementation in ADF

import org.apache.myfaces.trinidad.util.Service;

FacesContext fctx=FacesContext.getCurrentInstance();
       ExternalContext ectx=fctx.getExternalContext();
//      ectx.redirect("test1.jspx"); // to open in same tab
       ExtendedRenderKitService erks =
       Service.getService(fctx.getRenderKit(), ExtendedRenderKitService.class);
       String url = "window.open('" + "
reports.jspx" + "','\"_self\"','\"toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=600,height=500\"');";
       erks.addScript(FacesContext.getCurrentInstance(), url);
       ///code to open reports in pop up///

Friday, 6 September 2013

truncate output text or see more implementation - ADF output text tutorial-11

Some time we have requirement to show only a fix length of text in UI and show remaining text on demand.Oracle ADF provides this functionality out of box.
In the property of OutputText we can find truncate at

It truncates the text at 10, or it can be decided by an EL or java method return

In the above example text is  truncated on 10th letter and then ... is appended to show there is more text.Hovering the mouse above text will show the whole content.

Sunday, 25 August 2013

getting the DB connection from Weblogic datasource / JNDI

If you have any java/J2ee/ADF project deployed to a weblogic server and you have already created data source for DB connection. You can also get the DB connection in the java code for any specific task.
So here it goes.

public static Connection getConnection(String dsName) throws NamingException,
SQLException {
Connection con = null;
DataSource datasource = null;

Context initialContext = new InitialContext();
if (initialContext == null) {
datasource = (DataSource)initialContext.lookup(dsName);
if (datasource != null) {
con = datasource.getConnection();
} else {
System.out.println("Failed to lookup datasource.");
return con;

Remember this will create a new DB connection. So after getting the job done make sure you close this connection

Wednesday, 14 August 2013

ADF Custom validators for input text

ADF is very rich in providing validations out of the box whether client Side or Server Side.
Its safe to provide server side validations as well so that no can escape the validations by turning off js.
Here are the some default validators provided by ADF.
1.  ByteLengthValidator
2. DateTimeRangeValidator
3. DateRestrictionValidator
4. DoubleRangeValidator
5. LengthValidator
6. LongRangeValidator
7. RegExpValidator

Let's start making some custom Validators. I am starting with an EmailValidator
Make a Validator Class.

package com.rk.validator;

import java.io.Serializable;

import java.util.regex.Matcher;

import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class EmailValidator implements Serializable, Validator {

    public EmailValidator() {

    public void validate(FacesContext facesContext, UIComponent uiComponent,
                         Object object) {
        String value = (String)object;
        if ((value == null) || value.length() == 0) {
            System.out.println("null value found");
            //System.out.println("null value found");
        //String expression="^[\\\\w\\\\-]([\\\\.\\\\w])+[\\\\w]+@([\\\\w\\\\-]+\\\\.)+[A-Z]{2,4}$";
        String expression =
        CharSequence inputstr = value;
        Pattern pattern =
            Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputstr);
        if (!matcher.matches()) {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                          "Enter the proper Email Id",


Now go to faces-config.xml and open validators tab give a meaningfull Id like EmailValidator and classname
in this case it should be com.rk.validator.EmailValidator

and the input file just write
<af:inputText label="Enter EmailID" id="it1" autoSubmit="true">
<f:validator validatorid="EmailValidator"/>

And you are done.

Saturday, 20 April 2013

logout in oracle ADF / expiring session in ADF

One of the way of logging out user is ::

public String logout() throws IOException {
    ExternalContext ectx=FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse resp = (HttpServletResponse)ectx.getResponse();
HttpSession sess = (HttpSession)ectx.getSession(false);
return null;

Sunday, 3 March 2013

get user's details / Browser's details in Oracle ADF

        RequestContext rCtx = RequestContext.getCurrentInstance();
        FacesContext fctx=FacesContext.getCurrentInstance();
        Agent agnt = rCtx.getAgent();
  1.         //Get user's Browser's engine name
        String browser = agnt.getAgentName();

     2.   //Get user's Browser's engine version
        String browser_version = agnt.getAgentVersion();

    3. //Get user's IP address
        String userIpAddress =                      ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteAddr();
     4.   //Get user's Platform
        String platform = agnt.getPlatformName();
      5. //Get user's Platform's version
        String platformVersion = agnt.getPlatformVersion();
        Map reqHeader=
     6. // Get the User agent