Archive for August, 2004

Easy toString/equals/hashcode

A simple, standard and reusable way of creating toString, equals and hashcode methods in your classes/beans can be found in the jakarta commons.lang package:

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
public class BaseBean {
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
    public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
    }

    public int hashCode() {
//             EDIT: this hashCode-implementation seems to break Hibernate:
//             it throws a LazyInitializationException
//    return HashCodeBuilder.reflectionHashCode(this);
//
//             using this implementation for now
        return new HashCodeBuilder(25, 71) // random odd numbers
                .append(this.getId())  // a field in BaseBean, not shown for brevity
                .append(super.hashCode()) // using the standard hashcode too
                .toHashCode();
    }
}

New Oracle JDBC driver

After getting a weird NullPointerException using Transaction.commit() in Hibernate during an insert (eventually calling PreparedStatement.clearParameters() which was the source of the exception), it turned out that the JDBC driver in classes12.jar is outdated, and will not work on JDK1.4 and an Oracle 10g database.
Download the new drivers here to prevent unsuspected errors such as this one..

HTML-DB at a glance

Today I tried to put all my biases (I’m a j2ee developer) aside, and had a look at HTML-DB.

“Oracle HTML DB is a declarative web-based application development environment for the Oracle Database;. It helps anyone—even those with little to no programming skills—build data entry and reporting applications for the web. “

This quote is from a short introduction what HTML DB is and how it is positioned by Oracle posted on OTN Click here

This is a viewlet demostrating some development work in HTML DB.
Allthough I’m still haven’t made up my mind up completely of what I think of it , it was more impressing than I thought.
This link leads you to the HTML DB start page on OTN. Here you also request a workspace to try HTML DB without having to install it yourself. I tried it and it works like a charm. I created an application based on some Excel data within 3 minutes, complete with data entry and reporting facilities. It even included an SVG diagram!

Oracle has also created the HTML DB studio. Here users can add Utilities templates and applications they built and want to share with their collegues.

It is not J2EE, but in certain scenario’s it could be quite usefull. It really deserves further looking into

Any takers on some more in depth research?

Image buttons in Struts (using ImageButtonBean class)

Basically, the recipe for using image buttons using the Struts tag library can be found on this page at j2ee.lagnada.com and this excerpt uit Ted Husted’s book Struts in Action.

Read on to see what I have to add to this. Read the rest of this entry »

Formatting HTML forms part II

After my post on HTML forms yesterday I was fooling around with the fieldset and label tags. Both seem quite usefull! But Internet Explorer is really quite bad at rendering the fieldset. My 4-year old daughter does a better job of coloring inside the lines

fieldset in IE

Mozilla Firefox is much better
fieldset in IE

Another thing to keep in mind is the behaviour in JavaScript. HTML 4.0 compliant browser add the fieldset to the form.elements[] array. Older browsers don’t. Using position based indices is not portable in this case (myForm.elements[ 2 ]), you should use name based indices (myForm.elements["password"]). Labels on the other hand are not added.

If you want to use the labels in a struts tag you should do it like this.

<label for="password">Password </label><html:password property="password" styleId="password"/>

Clicking on the label will put the focus on the corresponding field. In case of a checkbox clicking on the label either checks or unchecks the box. Nice!

Hibernate kickstart

A quick’n dirty tutorial-by-example for Hibernate:
(Using one table, an Oracle9+ database and Hibernate2)

1) download the Hibernate distribution

2) put these jarfiles in /WEB-INF/lib:

hibernate2.jar (hibernate core)
cglib-full-2.0.2.jar (runtime class-enhancing)
dom4j-1.4.jar (xml reading)
ehcache-0.9.jar (objectcache)
c3p0-0.8.4.5.jar (connectionpool)
jta.jar (transactions)
Read the rest of this entry »

Databases for absolute beginners

Preparing slides for a presentation on Open Source Database Systems, I stumbled upon Open Source Database Systems, a neat 15 page PDF document, introducing (open source) databases, SQL, hardware requirements for database servers and concepts such as ACID.

If you are new to databases, this document can get you started in 30 minutes!

Formatting HTML forms

Allthough not earthshaking there is a nice article on the devshed about formatting HTML forms. Click here

The highlights for me are the tabindex, the accesskey and the fieldset. In one of our projects we built an HTML application with a lot of data entry. The users quite rightly were a little bit worried about having to navigate with the mouse for everything they had to do. Introducing the accesskeys and the tabindex completely removed the mouse from the picture. A simple, effective but often forgotten way to achieve user friendliness of your application.

The fieldset was completly new for me. An elegant way to enhance appearance of your form.

Multiple-level nesting with <logic:iterate> in Struts

I expected multiple-level nesting with the <logic:iterate> tag in Struts to be difficult, but on the contrary it turned out to be an almost trivial exercise. Read the rest of this entry »

JDBExplorer: a test-drive

Even though I started a journey into the realms of Open Source software available for Oracle , I’m taking a small detour now. JDBExplorer was suggested to me via a comment on Oracle Open Source: TOra (toolkit for Oracle).
As promised I have taken a look at it and now I’m posting my findings.

This 100% Java utility supports PL/SQL and Java development in Oracle Databases. Currently it’s only available for the Windows platform. The website indicates a linux-version to be underway.
Read the rest of this entry »