The following lines of code did not work as I expected:

Date monthStartDate = null;
Date monthEndDate = null;
dateTimeUtil.fillStartAndEndDate(date, monthStartDate, monthEndDate);

getLog().info("START: " + monthStartDate);
getLog().info("END: " + monthEndDate);


And the fillStartAndEndDate method:

public void fillStartAndEndDate(Date date, Date start, Date end) {
DateTime dateTime = new DateTime(date.getTime());

int startDay = dateTime.dayOfMonth().getMinimumValue();
DateTime startDate = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), startDay, 0 ,0 ,0 ,0);
int endDay = dateTime.dayOfMonth().getMaximumValue();
DateTime endDate = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), endDay, 0 ,0 ,0 ,0);

start = jodaDateTimeToJavaDate(startDate);
end = jodaDateTimeToJavaDate(endDate);
}


The results were the following:

START: null
END: null


This is one of those very basic things I sometimes overlook. At first, I thought that object reference in java works the same as the object reference in c++. In java, after creating a new instance of the object, the object (start param variable on the example) is not anymore pointing to the same reference which makes the method's local variable have a different value from the one that was originally passed.

I've written a pom.xml that will emanage the dependencies using maven. The following is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:artifact="antlib:org.apache.maven.artifact.ant"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.reyjexter</groupId>
<artifactId>exacto</artifactId>
<name>exacto</name>
<version>1.0</version>
<packaging>war</packaging>

<repositories>
<repository>
<id>jboss</id>
<name>The JBoss maven repo</name>
<url>http://repository.jboss.com/maven2/</url>
</repository>
</repositories>

<parent>
<groupId>org.jboss.seam</groupId>
<artifactId>root</artifactId>
<version>2.0.1.GA</version>
</parent>

<build>
<finalName>exacto</finalName>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>

<echo>***Deleting WEB-INF/lib dir</echo>
<delete>
<fileset dir="web/WEB-INF/lib" includes="**/*.jar"/>
</delete>

</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<webappDirectory>/web</webappDirectory>
</configuration>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<exclusions>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
<exclusion>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.el</groupId>
<artifactId>jboss-el</artifactId>
</exclusion>
<exclusion>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-ui</artifactId>
</dependency>

<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
</dependency>

<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-debug</artifactId>
<version>2.0.1.GA</version>
</dependency>

<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-api</artifactId>
<version>3.1.3.GA</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.richfaces.framework</groupId>
<artifactId>richfaces-impl</artifactId>
<version>3.1.3.GA</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</exclusion>
<exclusion>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-ui</artifactId>
<version>3.1.3.GA</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</exclusion>
<exclusion>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

</project>

The code simply removes the jar libraries from web/WEB-INF/lib and copies the maven dependencies to that folder.

I'll be posting a different configuration for ear and ejb jar in a couple of days

New EBJ 3 book

Knowledge in EJB is very important when studying seam framework because the framework itself was designed to be tightly coupled with ejb (although pojo's can also be used when developing applications, i think seam works better with ejb).

A week ago, the book I ordered from amazon arrived. The book entitled "EJB 3 In Action" from manning publishing covers the basics and important parts of ejb framework that is commonly used. Having read the book "Hibernate In Action" book from the same publisher, I think this book will be easily understood by people new to ejb 3.

Here are fresh from the box screenshots :D











Joda time and Seam / EJB

To use joda time libraries in seam project, simply copy joda-time-1.5.jar to PROJECTNAME-ear project folder and add the following in your application.xml:

<module>
<java>joda-time-1.5.jar</java>
</module>


When restarting jboss app server, the library for some unknown reason is not copied to deploy directory and Exception saying that joda time library cannot be found. Just copy the jar for to
PROJECTNAME-ear.ear folder in jboss deploy dir (for exploded deployment only)

I was trying to look for an easier way to clone objects (easier than using java.lang.Cloneable class) and I found out that using the jboss serialization library is easier and faster. The following code shows how to clone an object:

try {
JBossObjectOutputStream jbossSerializer = new JBossObjectOutputStream(null);
User newUser = (User) jbossSerializer.smartClone(user);
System.out.println(newUser);
}
catch(Exception e) {
System.out.println("EXCEPTION CAUGHT: " + e.getMessage());
}


using jboss serialization, you can also clone "Non serializable" objects.

you will need jboss-serialization.jar


Reference:

http://blogs.jboss.com/blog/clebert/

Newer Posts Older Posts Home

Blogger Template by Blogcrowds