Archive

Archive for November, 2009

Resizable JSF Components Using PrimeFaces

November 28, 2009 shunmugakrishna 4 comments

Introduction

Whenever I surf the net, I used to ponder whether there is any options that allows the end user to resize the components of  a web application developed in JSF. But in all this failed to discover a component like that. But now Primefaces has got the option to resize any components in JSF. Once again I was impressed at the peculiar features of Primefaces which has a resizable component that has the ability to resize all the components of JSF. Even I tried this out in Richfaces Panel, this worked without any conflicts. In this article I am going to explain how to implement a resizable option for the Richfaces panel and data table columns. This would be helpful to see the long data((ie)Wrapped data) in the column of a data table.

Prerequisites

  • IDE – Your favourite IDE
  • Tomcat 6.x/Glassfish/Jboss
  • JDK 1.5 and above

I assume that you had configured the Primefaces in your favourite IDE and now in this article let us see a sample , how to implement the resizable tag for the Richfaces panel  and the data table column. Read more…

Data Exporting in JSF Using PrimeFaces

November 27, 2009 shunmugakrishna 8 comments

Introduction

In this article we shall learn how to export the jsf data table content from the web page to a pdf, xls, xml and csv format in a JSF application, that may be very useful while generating a report . Now we are going to use a component library named Primefaces, which has more than 70+ ajax powered components that enriches our web application with rich look and feel. So here we are going to invoke a Primefaces component named Data Exporter which is used to export the datas in the web page to a  pdf, xls, xml and csv format. I am damn sure, Primefaces reduces the complexity for the developers while constructing a report for a web application.

Prerequisites

  • IDE – Your favourite IDE
  • Tomcat 6.x/Glassfish/Jboss
  • JDK 1.5 and above

I assume that you had configured the Primefaces in your favourite IDE and now in this article let us learn by a sample “Seven wonders of the world” represented in a datatable and let us see how the datas in the data table are exported  in to a PDF, xls, xml and csv format. First let  us begin by creating a backing bean Read more…

JSF and Richfaces configuration in Netbeans 6.x

November 22, 2009 shunmugakrishna 3 comments

Introduction:

JSF (Java Server Faces) is an java based  framework  for developing web application . Also component library can be easily incorporated in to the JSF Application. I have listed the most used components libraries by the developers in the below.

But this articles explains the Installation guidelines of Richfaces with JSF in Netbeans 6.x. Additionally learn how to create a hello world application in JSF using Richfaces. I assume that you have the requirements which I had mentioned below

Requirements:

  • IDE – Netbeans 6.x
  • Tomcat 6.x/Glassfish/Jboss
  • JDK 1.5 and above

Configuration Steps:

Configuring Richfaces with JSF application in Netbeans6.x can be accomplished by 4 easy steps Read more…

Java Code to Convert PDF Using Itext jar

November 19, 2009 shunmugakrishna 47 comments

Introduction

This article specifies a simple Java code to convert any kind of files to a PDF using iText jar. First let me give a small intro about the usage of  iText jar, which is an open source library used for creating and manipulating PDF, RDF and HTML files with the use of Java code. Thats Ok!! Let us come to the point, this article is consecrated for the peoples who wants to convert their files in to a PDF format using Java code. Download the latest iText jar here.

Note: I have used Apache Commons – IO jar to write the file’s text content to the PDF.

package com.sample.pdfconvertor;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
/**
 *
 * @author shunmuga
 */
public class PDFConversion
{
 /**
 * This method is used to convert the given file to a PDF format
 * @param inputFile - Name and the path of the file
 * @param outputFile - Name and the path where the PDF file to be saved
 * @param isPictureFile
 */
 private void createPdf(String inputFile, String outputFile, boolean isPictureFile)
 {
     /**
     * Create a new instance for Document class
     */
     Document pdfDocument = new Document();
     String pdfFilePath = outputFile;
     try
     {
         FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
         PdfWriter writer = null;
         writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
         writer.open();
         pdfDocument.open();
         /**
         * Proceed if the file given is a picture file
         */
          if (isPictureFile)
         {
          pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
         }
         /**
         * Proceed if the file given is (.txt,.html,.doc etc)
         */
         else
         {
         File file = new File(inputFile);
         pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
         }

         pdfDocument.close();
         writer.close();
     }
     catch (Exception exception)
     {
      System.out.println("Document Exception!" + exception);
     }
  }

  public static void main(String args[])
  {
   PDFConversion pdfConversion = new PDFConversion();
   pdfConversion.createPdf("C:/shunmuga/tajmahal.jpg", "C:/shunmuga/tajmahal.pdf", true);

// For other files
   // pdfConversion.createPdf("C:/shunmuga/sample.html",
   //"C:/shunmuga/sample.pdf", false);
   }
}

So by invoking above code any file can be converted in to a PDF format file. If you find this article is useful to you dont forget to give your valuable comments. Have a joyous day.

Hello world!

November 9, 2009 shunmugakrishna 1 comment

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Categories: Uncategorized