Sep 20, 2015

Using html in jasper ireport

Sometimes we required to use html tag in jasper ireport.

we can use html in jasper using two methods.

  •  Using Html component 

            You can use Html component to get required output of html script.


            Drag and drop Html component and select HTML Content Exp.  property.

            
            Provide appropriate Expression and click on Preview to run the report.

  • Using Markup property of a Text Field


           You can also use Markup Property of Text Field to show text in html scipt.

           Select a Text Field and goto Markup Property 


           Select html from the list 



           Provide appropriate html Scipt in Text Field Expression of Text Field.

           Click on Preview to run the report.



Sep 18, 2015

Date format and custom date format in jasper ireport

Date format


There are many date format available in jasper ireport to choose from.

To choose from date format available in jasper ireport select Text Field.


  • Go to Pattern  Property of selected Text Field.





  • Click on right icon to select from list.





  • You will see Different Category , select Date Category .





  • Now different type of Pattern is available for date , select required pattern and click on OK.


          For example I have select Pattern dd/MM/yyyy




  • Now Click on Preview to run your report.


You can change Pattern at any part of time as per your requirement.


Custom Date format


Sometimes it is required to change date format dynamically.
You can change date format run time dynamically .

  • For same you have to create a Parameter of type java.lang.String and its value can be change at run time.


For example I have created a Parameter DateFormat of type java.lang.String.

  • Go to Pattern Expr.  Property of selected Text Field.

  • Click on right icon to Select Parameter.

  • Now Click on Preview to run your report.
          Pass parameter value as per java recommender Date Format.

Using java SimpleDateFormat

You can also use java SimpleDateFormat to required date format.

Add following expression in Text Field Expression

new SimpleDateFormat(Date_Format).format(Database_field)

where Date_format is Pattern value as per your requirement 
and Database_field is database field which need to be formatted(must be Date data Type).







textField with pattern performers faster than new SimpleDateFormat("Date_Format").format("Database_field"). 
It's important when you have deal with huge reports.

Sep 17, 2015

Use IN clause of sql in jasper ireport

Sometime it is necessary to pass IN clause of sql in jasper ireport.

You can use following syntax

select ... where $X{IN, database_column_name, parameter_name}

parameter_name  is a parameter name  of type Collection or array.
Your parameter to be of type java.util.Collection or java.util.List.

database_column_name is database column name.

With the $X{} syntax, the word IN is the name of the function (the other choice is  NOT IN).




Sep 15, 2015

Create New database connection or datasource in ireport

Following step is required to create New database connection.

1.) You have to click on Report Datasources.


   Selected Connection/Datasource is shown just beside Report Datasources.



2.) To create New Connection/Datasource click on Report Datasources
     
    


New Dialog Box will be opened which contains all Connections/Datasources Name

3.) Click on New to create new Connection or click on Modify to modify available    Connection/Datasources .

When you will click on New , a new dialog box will open to select Datasource Type.


4.) Select Database JDBC connection to create database Connection and click Next.


5.)Provide Connection name.



6.) Select JDBC Driver from list
   

7.) Now select Oracle Driver from List


      If you have not installed Oracle Driver then Install Oracle Driver.

8.) Now provide JDBC URL ,Username, password and select Save password check box to save the password.


 9.)Now click on Test  to test the connection .


Once you connection test is successful then click on Save to save the Connection.


10.)When you save the connection , Connection will  appear in Connections/Datasources name






Now click on Close to close the dialog box .


Now New Created is set as default connection .

You can create as many as connections but only one will be default at a time.



Sep 14, 2015

Installation of oracle database driver in ireport

Following steps are required to install oracle database driver in ireport

1.) Goto Windows Menu bar and click on Services or press Ctrl+5






2.)  Now you will see databases driver listed in service window.



3.) To add database driver right click on Driver folder and click on New Driver.




4.) New window is opened .

    


5.) Click on Add to browse and select ojdbc6.jar jar file save in system.

     In Driver Class section oracle.jdbc.OracleDriver is selected and name as Oracle Thin.




   Now click Ok to finish Installation.

6.) Now you will see Oracle Thin driver has been installed and showing in Driver List.




 

Installation of jasper ireport

Before starting the installation make sure java is installed in your system.

You can download ireport installation file and jar file from jasper community site  ireport setup file.

Double click on installation file.

1.)

The first step introduces the installer and allows you to continue or exit. Click Next.

2.)

 You are prompted to read and accept the license agreement. Read the agreement, agree to the terms by clicking 
 I Agree

3.)
click on Next button to start installation.

4.)


You are prompted for the directory where Jasper ireport is installed referred to as the Jaspersoft  directory. Accept the default or click Browse and select a different location, and click Next.

5.)


Now click on Install button to start Installation.

6.)



wait sometime to complete installation process.
7.)

now click on Finish to finish installation.


Sep 10, 2015

show image from path in oracle adf

I have posted how to upload image in path or in database Blob column Upload Image in server.

Now next is how to show image on Page.

For same we have to use Servlet.

  •  Create Servlet.







  • Now use following below code to in Servlet to show image   
       
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.*;
import javax.servlet.http.*;

public class ImageShowServlt extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = (request.getParameter("path"));


        OutputStream os = response.getOutputStream();
        if (path.equalsIgnoreCase("No")) {
            path = "D:\\Document\\UserImage\\User.jpg";
        }
        if (request.getParameter("path") == "") {
            path = "D:\\Document\\UserImage\\User.jpg";
        }
        InputStream inputStream = null;

        try {

            File outputFile = new File(path);


            inputStream = new FileInputStream(outputFile);
            BufferedInputStream in = new BufferedInputStream(inputStream);
            int b;
            byte[] buffer = new byte[10240];
            while ((b = in.read(buffer, 0, 10240)) != -1) {
                os.write(buffer, 0, b);
            }


        } catch (Exception e) {

            System.out.println(e);
        } finally {
            if (os != null) {
                os.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }

        }
    }
}


  Servlet process image file into bytes and then show image using af:image component.

 Pass image path as HttpServletRequest parameter to Servlet from Managed Bean or binding on page.

  For this create a managed bean with variable name path.

Generate variable Accessor.






Now run application