Archive for April, 2009

What are the differences between SAX and DOM parser.

April 18, 2009 Leave a comment

Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.



Parses node by node

Stores the entire XML document into memory before processing

Doesn’t store the XML in memory

Occupies more memory

We can’t insert or delete a node

We can insert or delete nodes

Top to bottom traversing

Traverse in any direction.

SAX is an event based parser

DOM is a tree model parser

SAX is a Simple API for XML

Document Object Model (DOM) API

import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

import javax.xml.parsers.*;
import org.w3c.dom.*;

doesn’t preserve comments

preserves comments

SAX generally runs a little faster than DOM

SAX generally runs a little faster than DOM


If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.


More Info:  SAX Parser is the one which is developed to run the java programs especially. It uses a memory resident model. DOM is developed by w3c consortium so that it is an open standard. In DOM the xml file is arranged as a tree and backward and forward search is possible for searching the tags and evaluating the data which it holds. It depends upon the application and ease of data accessiblity. If we want to extract the data from a xml file once we have to move to SAX which is one time top to bottom read approach and if we want ot randomly pick the data in an xml file then the tree reperesentation of DOM model is to be put into use.

Categories: Java

How to read values from properties file in JBoss Seam

April 11, 2009 Leave a comment
Let us assume we have two properties files namely and

In components.xml we place the below line

<core:resource-loader bundle-names=”messages application”/>

Then in the Seam component where we want to retrieve the value for a given property (key), we inject the ResourceBundle as below.

    java.util.ResourceBundle resourceBundle;

The retrieval is done as below

String imagesLocation = resourceBundle.getString(“IMAGESLOCATION”);
Categories: Jboss Seam Tags:

JSF Validation – restricting minimum and maximum length for a textarea

April 11, 2009 Leave a comment

Restricting text length in textarea in JSF can be done as below.  Here we restrict the maximum length to be 390 and the minimum length to be 10. Please note that these restrictions will be applied only when the required attribute is true.

      <h:inputTextarea  required=”true” cols=”70″ rows=”9″ id=”message” value=”#{inviteaction.message}”>
          <f:validateLength maximum=”390″ minimum=”10″/>

where f and h namespaces are configured as 


Categories: JSF

Signing a JAR file

April 11, 2009 Leave a comment

JDK is to be installed and make sure the bin folder under Java
installation home folder has keytool.exe and jarsigner.exe and are available in the PATH.

Assuming the algorithm used to generate key is RSA, execute the following command navigating to the directory in which jar file resides[let us assume the name of the jar file to be signed is testapplet.jar].

keytool -genkey -alias keystorename -keyalg RSA -keypass urpassword -keystore appkeystore.jks -storepass urpassword

You will be prompted to enter values for your state, oraganisation etc.
Enter appropriate values and then execute the following commandto
complete the signing of the jar file.
jarsigner -keystore appkeystore.jks testapplat.jar keystorename

Example : keytool -genkey -alias COREDEV -keyalg RSA -keypass urpassword -keystore appkeystore.jks -storepass urpassword

Categories: Java

Command to skip test using maven

April 10, 2009 Leave a comment

mvn -Dmaven.test.skip=true clean install

-Dmaven.test.skip=true — will skip the tests in the module.

Categories: Maven Tags: ,

Navigation in Seam/JSF

April 8, 2009 Leave a comment


Seam also allows you to specify navigation rules in pages.xml. This can be more convenient than specifying navigation in the typical JSF way.

Take the following JSF navigation rule, for example:

        <from-view-id>/pagewithlink.xhtml</from-view-id>  (1)
            <from-outcome>first</from-outcome>            (2)
            <to-view-id>/first.xhtml</to-view-id>         (3)
            <redirect/>                                   (4)
  1. The view id of the page that produces the outcome.
  2. The outcome id.
  3. The destination view.
  4. Optional redirect tag for redirect after post

Using Seam, this can be represented in pages.xml as:

  <page view-id="/pagewithlink.xhtml">       (1)
      <rule if-outcome="first">              (2)
        <redirect view-id="/first.xhtml"/>   (3)
  1. The view id of the page that produces the outcome.
  2. The outcome id is specified using <rule if-outcome="...">.
  3. The destination is a redirect element in this case.

Not only is this more compact than the JSF way, it is also possible to eliminate the outcome strings from the application and replace them with EL expressions using <rule if="... EL expr"> syntax:

  <page view-id="/pagewithlink.xhtml">       (1)
      <rule if="#{theSfsb.goodToGo}">        (2)
        <redirect view-id="/first.xhtml"/>   (3)
  1. The view id of the page that produces the outcome.
  2. Instead of specifying an outcome string, we use an EL expression to invoke a method on a SFSB which will return a boolean.
  3. The destination is the same  redirect element

No more nasty outcome strings in the EJB!

Categories: Jboss Seam Tags: ,

No phase id bound to current thread (make sure you do not have two SeamPhaseListener

April 8, 2009 Leave a comment

This error occurs if you have two jboss-seam-*.jar in the deploy folder of the jboss. Please make sure to have only on jboss seam related jars.

Categories: Jboss Seam Tags: