Archive for February, 2007

HTML Radio Buttons

Tuesday, February 27th, 2007

Well… what if you have a group of two (or more) radio buttons and want to use the onchange event like this:

<input type="radio" name="xpto" value="One" onchange="onChangeHandler()" checked/>

<input type="radio" name="xpto" value="Two" onchange="onChangeHandler()"/>

When the onChangeHandler is fired up, which value is on our radio button form parameter “xpto” ? The old one? Or the new one?

It’s Just a matter of your web browser choice: If you use Firefox you’ll get the new value. But if you use Internet Explorer you’ll get the old one!

What about that?

For my case, where I wanted the new value, I’ve just starting using onclick and filter when the same value is selected.

Java Persistence API, Hibernate Annotations and Maven2

Wednesday, February 14th, 2007

Setting up a project with Hibernate Annotations using Maven2 is quite simple… or at least it should be. You should just have to set up your pom.xml file with the following dependencies:


<project>

...
<dependencies>
<dependency>
<groupid>hibernate</groupid>
<artifactid>hibernate-annotations</artifactid>
<version>3.2.1ga</version>
</dependency>
</dependencies>
...
</project>

And this is what I expected to start using Hibernate Annotations on my project. But if you try to compile your project you’ll get the following:


...
Missing:
----------
1) hibernate:hibernate-annotations:jar:3.2.1ga


Try downloading the file manually from the project website.

Then, install it using the command:


mvn install:install-file -DgroupId=hibernate -DartifactId=hibernate-annotations \
-Dversion=3.2.1ga -Dpackaging=jar -Dfile=/path/to/file


Path to dependency:
1) ...
2) hibernate:hibernate-annotations:jar:3.2.1ga

So, Maven couldn’t resolve our dependency but at least gave us a hint on how to solve the problem. After downloading the Hibernate Annotations 3.2.1GA file and unzip it, we used the suggested command to solve the problem:

mvn install:install-file -DgroupId=hibernate -DartifactId=hibernate-annotations -Dversion=3.2.1ga -Dpackaging=jar -Dfile=hibernate-annotations.jar

After successfully installing the package, the project successfully compiled!

The problem is that usually we don’t want to use Hibernate Annotations by itself, we want to use the Java Persistence API (JPA) which is included on the javax.persistence package. So by including another dependency on our pom.xml like this:

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>ejb</artifactId>
<version>3.0-public_review</version>
</dependency>

we get a similar error as we did when we tried to use Hibernate Annotations. Maven can’t resolve the dependency, but this time it even give us a hint where to dowloand the missing library:

Missing:
----------
1) javax.persistence:ejb:jar:3.0-public_review

Try downloading the file manually from:
http://prdownloads.sourceforge.net/hibernate/hibernate-annotations-3.1beta5.tar.gz?download

Then, install it using the command:
mvn install:install-file -DgroupId=javax.persistence -DartifactId=ejb \
-Dversion=3.0-public_review -Dpackaging=jar -Dfile=/path/to/file

If you notice, the URL where we can download the missing library is pointing to Hibernate Annotations! Since we already have downloaded Hibernate Annotations and it’s an earlier version than the suggested we just have to find out where the jar containing the javax.persistence is. And it’s on the ejb3-persistence.jar under the lib directory.

Issuing the installation command on the file, and you’re ready to go! Just type the following to install the jar on the local Maven repository:

mvn install:install-file -DgroupId=javax.persistence -DartifactId=ejb -Dversion=3.0-public_review -Dpackaging=jar -Dfile=ejb3-persistence.jar

That’s it! Not so fun using Maven when the dependencies aren’t resolved “automagically” like the most, but it still is a fantastic tool for managing your Java projects!

Setting up a web project using Maven 2

Tuesday, February 13th, 2007

Setting up a web project using Maven 2 is the simplest thing in the world. You just have to type in:


mvn archetype:create -DgroupId=groupId -DartifactId=TestWebapp -Dpackagename=your.package.name -DarchetypeArtifactId=maven-archetype-webapp

Et voila! A new directory with your project name is created with the full directory structure of your web application. Lets take a look on what’s inside of our project directory:

Directory structure

Inside our TestWebApp we can found our newly created pom.xml with a JUnit dependency already setup.

The rest of the structure is pretty intuitive. On src you’ll find a directory with our main sources. Under this directory (src) we have resources where we put all properties and configuration files, webapp is where all files related with our web application goes (jsp, images, javascripts, stylesheets, etc.) including the WEB-INF stuff under the directory with the same name. The java files are under a directory that is not created initially by the archetype, but of course it’s named java .

This archetype doesn’t create our test directory, but it’s pretty straight forward since it’s same structure as main but it’s named test (and also lives under the same directory src as we would expect to). To run our tests we just have to type mvn test.

After completing the structure by creating the java and test directory we have the following project structure:

Complete Directory Structure

To create the WAR file we just have to type in mvn package and all the maven life cycle phases run, including building all source files, resolving dependencies, testing and packaging our WAR file.

Running this command for the first time will take a little longer, since Maven needs to download all necessary files (including our project dependencies) to complete the requested task. On success, Maven will deploy our WAR file on the target directory under the root directory where all compiled classes are!

Simple isn’t it?

Welcome

Friday, February 9th, 2007

This is the weblog for my company: RUPEAL

RUPEAL is a startup company who’s purpose is to develop software and human resources that bring innovation and excelence to the business of our clients.

We’ve just started our journey, and this blog is meant to share our experience on creating a company from scratch.

Hope you enjoy!