Tag Archives: appfuse

Error deploying AppFuse application on Tomcat

When trying to deploy an AppFuse application on Tomcat I received the following error:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 153 in the generated java file
Type mismatch: cannot convert from null to int

An error occurred at line: 168 in the generated java file
Cannot cast from Object to int

The source of the error turned out to be due to the Constants.java file containing a variable that was not a String. Changing it into a string (and add appropriate type-casting in the application) got rid of the error.

Date fields in forms using Spring and AppFuse

I had some problems getting date fields to work (and return a friendly error message) so here comes a little documentation for future reference. This was in an AppFuse based Spring Framework project.

The model contains a java.util.Date property and simply exposing it as usual in a form will cause an exception since Spring doesn’t know how to convert the string into a Date:

Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property startTime; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property startTime: no matching editors or conversion strategy found

To solve this we need a custom property editor. It may be registered by overriding the initBinder() method of a controller. Spring already contains a CustomDateEditor that we may use for this purpose.

protected void initBinder(HttpServletRequest request, 
                          ServletRequestDataBinder binder) {
    SimpleDateFormat dateFormat =
        new SimpleDateFormat(getText("date.format", request.getLocale()));
    binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));

Note that you may replace the getText() call with a hard-coded “yyyy-MM-dd” or similar, at least for debugging purposes.

If it is an AppFuse project and the controller extends BaseFormController then you don’t need this since the CustomDateEditor is already registered in the BaseFormController.initBinder() method.

Now it should work, however, the error message isn’t especially user-friendly when entering an invalid date:

Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property startTime; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: “2008-37-09”

Better error messages may be provided using the resource file of the application (make sure you have a ResourceBundleMessageSource set up) by specifying typeMismatch error message for this type:

typeMismatch.java.util.Date={0} is an invalid date.

The {0} will be replaced by the property name, in this case startTime, which may not be desired. This may be overridden by setting a custom error message for this specific property:

typeMismatch.startTime=Start time is an invalid date.

Do also make sure to update validation.xml accordingly.

AppFuse and NetBeans: part 2

Some more tips about getting an AppFuse generated application into NetBeans.

  1. Pick archetype of choice, e.g.: mvn archetype:create -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring -DremoteRepositories=http://static.appfuse.org/releases -DarchetypeVersion=2.0.2 -DgroupId=com.mycompany.app -DartifactId=myproject
  2. Run mvn
  3. Generate full sources: mvn appfuse:full-source
  4. Install the Maven plugin in NetBeans (Tools / Plugins / Search for Maven).
  5. Open the project (located the pom.xml file)
  6. Right-click the project name and select Properties
  7. In categories, select Run. Chose a server.
  8. In categories, select Actions. Check the box for Use external Maven for build execution.
  9. In main window, select Tools / Options / Miscellaneous / Maven 2.
  10. Now Run the project, and after a while a browser should open pointing you to the login screen.

Manually run AppFuse WebTests

Sometime it may be useful to manually run the (Canoo) web tests for AppFuse applications to be able to see what goes wrong. Accomplish this by making the test web container pause upon start using:

mvn -Dcargo.wait

Then the application (using default values) is reachable at:


Where <app_name> might be something like appname-1.0-SNAPSHOT depending on your configuration.

If a test fails it might also be a good idea to take a look at how the pages retrieved actually look like, they are saved (by default) in the directory target\webtest-data.

AppFuse and NetBeans

Opening an AppFuse in NetBeans might be done in two ways, two ways that I managed to mix up the first time…

Either install the Maven plugin Mevenide2 for NetBeans, then you may simply open the Maven project generated by AppFuse directly. Without the Maven plugin, then you need to convert to project using mvn netbeans:netbeans (see previous post). Opening up a converted project with the NetBeans Maven plugin installed will result in badness.

Wondering where the source is? See this post.

Generate full-source with AppFuse

In AppFuse 2.x you don’t automatically get the full source of the generated project. To generate the source, run:

mvn appfuse:full-source

On my Ubuntubox this all went well, but on my work laptop running Windows XP it failed with the fatal error:

Illegal character in path at index 18: file:/C:/Documents and Settings/myuser/.m2/repository/org/apache/ant/ant/1.7.0/ant-1.7.0.jar

Turned out to be because of the spaces in the path, a not so uncommon problem for *nix stuff running under Windows.

To solve this you may either move your maven artifact repository to a path without a space, or edit the maven settings.xml so the path no longer includes a space. This is achieved by using DOS short names. To see what a files short name is, open the command prompt and run dir /X.

The settings.xml is likely located in the conf directory where you installed Apache Maven, in my case it was:

C:\Program Files\Apache Software Foundation\apache-maven-2.0.9\conf\settings.xml

I added an entry (if there is already one, edit it) for localRepository:


Now everything worked and I got BUILD SUCCESSFUL. Please note that the actual path is likely different on your setup. Change it as appropriate.