Category Archives: work

Tapestry 5: radio buttons coming back with value "on"

I ran into a problem today where I was setting the value of a radio button in Tapestry 5 to a long field within a property. I was getting back the value “on” and Tapestry was crashing trying to coerce it into a long type. It turns out the value was null, and the default value for a radio button is “on”. So, if you encounter this, make sure your value fields are not null.


The end of Netbeans week

I have finished my week of Netbeans usage and so far am pretty impressed. I was able to go all week without using Eclipse once. A large part of that is thanks to the fact that I’ve been using Maven 2 for a large number of my most recent projects. If you have a pom.xml, Netbeans will be able to check out your project and open it without you doing a single bit of configuration. This is great, since it goes a long way in preventing IDE lock-in. If you are working on a Maven project, you can use Netbeans easily, even if everyone else is using Eclipse. I didn’t get very deep into working on non-Maven projects, so that may have been quite a bit more hassle. All in all, though, Netbeans has come a long way since the last time I gave it a serious test. Here are some of my favorite features:

  • Autocomplete seems quite a bit faster than Eclipse
  • Maven integration is good, but I only briefly tried projects with parent-child relationships, which seemed to trip it up a bit
  • Adding getters/setters is a lot less hassle than Eclipse.
  • Using jetty:run right inside Netbeans was pretty easy, though it did require the use of external Maven, I’m not sure why.
  • The web.xml editor is pretty cool
  • It has a built in SOAP client, although it seems pretty clunky.
  • SVN integration seems complete and not very buggy. The interfaces are quick and simple, though I might say it’s a bit oversimplified from the way Eclipse does things.
  • The built in editor support for non-Java files seems less buggy than in Eclipse.

I may give Netbeans another week. It should be pretty obvious to anyone that it takes longer than a week to fully get a feel for such a complicated piece of software.

The modern Java web app

I’m always looking for ways to streamline Java web app development. In case I haven’t spread the word to you, here’s the current set of technologies I’m liking:

  • Tapestry 5 – This is the framework I’m using, but I’m not saying it’s better than anything in particular, but I like some of the stuff they are doing.
  • Hibernate with annotations – I’ve been a big fan of hibernate for a long time, using the annotations seems to simplify the mapping process quite a bit.
  • Spring Hibernate integration – makes transaction/error handling way way easier in Hibernate. I am using HibernateDaoSupport as a base class. Tapestry 5 also has Spring integration, allowing you to inject the DAO’s right into your page classes
  • Maven 2 – So much easier than ant and dependency hell, once you get used to the paradigm shift. It might cause issues with your Eclipse tomcat integration, but I always found that to be flaky anyway. Use Jetty instead.
  • Maven Jetty plugin – Allows you to build/deploy your app with one command (mvn clean jetty:run). Much easier than dealing with some of the flakiness of tomcat deployment, and allows you to just run one of your apps at a time.

I am also looking into Spring Security, and hoping it will simplify authorization, and I’m doing some IDE evaluations to see if it’s time to ditch Eclipse.

IDE of the week: Netbeans 6.1

Happy Monday morning. After battling with Maven and the Tomcat plugin in Eclipse a bit last week, I have decided to try some alternative IDEs. I’ve heard good things about IntelliJ, and I think the Maven integration in Netbeans is supposed to be good. So, I’ve decided to give each of them a week of use and see if they can beat out Eclipse. This week is Netbeans 6.1. So far, I’ve spent a few minutes installing updates and reading up on the Maven support (you have to install a plugin through the plugin manager). Now that the plugin is installed, it automatically recognizes Maven projects when I check them out, so that is cool. Hopefully I can make it through the week without reverting to Eclipse.

Tapestry 5: First Impressions

My new group at ASU is loosely standardizing on Tapestry, so I’ve been spending some time learning it. We are officially using 4.1, I think, since it’s the latest official release, but I decided to go all rogue style and switch to 5.0 after spending some time on 4.1. From the noise on the web, it sounds like Tapestry gets completely rewritten for every new version, so 5.0 is pretty different from 4.1. Anyway, it seems much better, but there are still some weird problems. Here are some of the interesting things I’ve run into:

  • If you need to call some Tapestry page from an outside app with data, you can simulate Tapestry’s “activation/passivation” by building URL strings which will feed your onActivate method. They look like this: http://localhost:8080/app/page/param1/param2, where param1 and param2 will be passed in a List (not an array, as I found out the hard way) to onActivate. I’m not sure if this is the best way to do it.
  • If you loop through a list of items and want to be able to edit those items (like by having a checkbox), you pretty much need to set up a PrimaryKeyEncoder, otherwise it will serialize/deserialize stuff and all your changes will be lost. This was very hard to figure out.

So far I’m only moderately impressed. There seem to be too many assumptions that don’t fit the model of my first app very well, but we’ll see how it goes once I get better at it.

Getting tomcat to stop deleting your context xml files

I’ve been plagued with this annoying problem in tomcat for about a year, and it has been driving me crazy. I’ve looked through the code, joined the mailing list, etc. etc. The problem is when you have context xml files, such as /usr/local/tomcat/conf/Catalina/localhost/app.xml. Generally, you would use such files to set up JNDI data sources for database connections, but I also use them to set up configuration beans in order to keep environment-specific data outside of your application code (which I consider the whole war file to be). Anyway, tomcat seems to randomly delete those files when I change anything in the application files. I tried various configurations using war files, no war files, and war files in funny locations, and it happened to all of them.

I never did find out why it deletes the files, but I did find a solution, thanks to a user on the tomcat mailing list. All you have to do is turn off “autoDeploy” on the “Host”. Basically, you need to edit /usr/local/tomcat/conf/server.xml and change the xml element, so that it says autoDeploy=”false” instead of autoDeploy=”true”. And with that, all my problems are over.

Hibernate error reporting

Sometimes, Hibernate is really bad at error reporting. Today I added a NOT NULL constraint to a column in my database and ran my unit tests. Several failed with errors like this:

testAddInstructor(edu.asu.cem.test.dao.CourseDAOTest) Time elapsed: 0.009 sec <<
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(
at org.hibernate.persister.entity.AbstractEntityPersister.insert(
at org.hibernate.persister.entity.AbstractEntityPersister.insert(
at org.hibernate.action.EntityInsertAction.execute(
at org.hibernate.engine.ActionQueue.execute(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.engine.ActionQueue.executeInserts(
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(
at org.hibernate.event.def.AbstractSaveEventListener.performSave(
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(
at org.hibernate.impl.SessionImpl.fireSave(
at edu.asu.cem.test.dao.CourseDAOTest.setUp(
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.junit.internal.runners.MethodRoadie.runBefores(
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(
at org.junit.internal.runners.MethodRoadie.runTest(
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(
at org.junit.internal.runners.JUnit4ClassRunner$
at org.junit.internal.runners.ClassRoadie.runUnprotected(
at org.junit.internal.runners.ClassRoadie.runProtected(
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(
at org.apache.maven.surefire.booter.SurefireBooter.main(
Caused by: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
… 44 more

I had made several changes since running the tests, so I had to think about what might be making a database call crash. Luckily, I was able to remember, but I have spent hours debugging these before. I wish the JDBC exception was floated to a higher point in the exception chain so it would be displayed. In this case, all I had to do was set a value for the fields that were no longer nullable.