Saturday, February 25, 2017

Programmatically Component Creation in ADF

Programmatically component creation and applying skining and validation on component programmatically.
          

  1. Create fusion ADF application and in view controller create page    
  2. Find a parent component to create child under it as any layout (panel form, panel group, af:form etc)
  3. Suppose you have a page with a panel form layout, now you have to create child components in this form layout at runtime   
  4. Dropped a button on page , on this button action i will create an inputText                                    programmatically and assign validator method reference to it.
  5. Create mananege bean class.
  6. Bind the form component value with manage bean .


     <af:panelFormLayout id="pfl1" binding="#{pageFlowScope.ProgramComponent.panelForm}">
                    <f:facet name="footer"/>
                </af:panelFormLayout>
    binding with panelForm:


                  























         add component method which help in adding component under the parent layout.


     

creating object of component and setting properties and calling add component .





create one helper method to resolve Validator 





and now add the validator into the input component 

ui.setValidator( resolveValidator("{pageFlowScope.ProgramComponent.inputValidator}"));















Thanks to ashish





Saturday, September 12, 2015

Integration of Oracle ADF with Jasper Report

An application using statistical data requires often to generate reports (PDF, XLS , Docx etc.) in order to provide a visual document with the selected information.
There are some tools to provide report generation, and I’d like to present you a comprehensive environment – Jasper with its template builder iReports.

There are 3 ways of populating data into the jasper Report through Oracle ADF.

Below are the following:

1. JavaBean Data source with Array Value.

2. JavaBean Data Source with Map value through parameter.(through collection)

3. Schema Data source(creating connection with Database)

In this post i am going to share  3rd one:

Integrating Oracle ADF with Jasper Report.

Setup before Start creating the application:

1- You download iReport-5.6.0 (http://sourceforge.net/projects/ireport/files/latest/download)

2- You have to database Oracle XE(http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html) and Grand the role to HR which already a part of schema.
3- Setup JDeveloper 11g.

Below are the steps:

Step1. In J developer Create ADF application and add the following libraries in the project:

1-commons-digester-1.7.jar
2-itext-1.4.5.jar
3-jasperreports-3.0.0.jar
4-poi-2.5.1-final-20040804.jar

5- jasper-compiler-jdt-5.5.15.jar

Add this libraries to your ViewController project ---> Right click on the project ---> Project Properties--->Libraries And Classpath ---> Add JAR/Directory

Step2. Now open iReport tool:

iReport has not oracle database driver so you use oracle database you should first add a ojdbc jar file to the classpath of iReport

In iReport goto Tools---> Options ---> Classpath and add ojdbc6.jar

Make a connection to Hr Schema

Both in iReport and Jdeveloper(Database navigator)



 
Step 3:Create Template in iReport and path is under your workspace/viewcontroller/ like below:




Step4:Create One Jspx page in ADF application and create a class which contain method of compilation and running the jrxml template which we are created in iReport tool:

The method is:

 public BindingContainer getBindings()
  {
    return BindingContext.getCurrent().getCurrentBindingsEntry();
  } 
  
  public Connection getDataSourceConnection(String dataSourceName) throws Exception
    {
      Context ctx = new InitialContext();
      DataSource ds = (DataSource)ctx.lookup(dataSourceName);
      return ds.getConnection();
    }
  
  private Connection getConnection() throws Exception
  {
    return getDataSourceConnection("hrDS");// use datasourse in your application
  }
  
  public  ServletContext getContext()
  {
    return (ServletContext)getFacesContext().getExternalContext().getContext();
  }
  
  public  HttpServletResponse getResponse()
  {
    return (HttpServletResponse)getFacesContext().getExternalContext().getResponse();
  }
  
  public static FacesContext getFacesContext()
  {
    return FacesContext.getCurrentInstance();
  }
  
  public void runReport(String repPath, java.util.Map param) throws Exception
  {
    Connection ds = null;
    try
    {
      HttpServletResponse response = getResponse();
      ServletOutputStream out = response.getOutputStream();
      response.setHeader("Cache-Control", "max-age=0");
      response.setContentType("application/pdf");
      ServletContext context = getContext();
      InputStream fs = context.getResourceAsStream("/reports/" + repPath);//we will put the report under folder "reports" under Web Content
      JasperReport template = (JasperReport) JRLoader.loadObject(fs);
      template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
      conn = getConnection();
      JasperPrint print = JasperFillManager.fillReport(template, param, ds);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      JasperExportManager.exportReportToPdfStream(print, baos);
      out.write(baos.toByteArray());
      out.flush();
      out.close();
      FacesContext.getCurrentInstance().responseComplete();
    }
    catch (Exception jex)
    {
      jex.printStackTrace();
    }
    finally
    {    
      close(conn);
    }
  }
  
  public void close(Connection con)
   {
     if (con != null)
     {
       try
       {
         con.close();
       }
       catch (Exception e)
       {
       }
     }
   }


Hope Blog will help you in integrating ADF with Jasper.