Cereal Hack Raffle Application

Willow Schlanger and I participated in the Cereal Hack this last weekend. We built a Raffle application. We both worked in parallel. Willow built a version in PHP and I did mine in Java. Willow’s app was the most functional in the time for our 3 minute presentation. We didn’t win any awards, but our presentation went well. I continued to work on my Java version. You can download my Java version at the following link:


raffle08.zip is the version at the time of this writing.

I hope to put a link to Willow’s code soon.


Posted in Uncategorized | Comments Off on Cereal Hack Raffle Application

Running JBoss Application Server

This is about the JBoss Application Server, commonly known as JBoss AS. I have some posts that need the JBoss application server. If you visit the JBoss website, you will notice many projects that fall under it. Make sure you look for the application server.

Download JBoss AS server from the download site. http://www.jboss.org




Unzip or untar it.


some_path$ tar zxf jboss-as-7.1.1.Final.tar.gz


c:\some_path> unzip jboss-as-7.1.1.Final.zip

Note the path where you started it. If you are using Maven from a different window, set the JBOSS_HOME to it in a different console. Replace <some_path> with the actual value.


 set JBOSS_HOME=<some_path>


 $ export JBOSS_HOME=<some_path>

After downloading it, change to the bin directory and start it as follows:


$ cd bin
$ ./standalone


c:\some_path> cd bin
c:\some_path\bin> standalone.bat

JBoss AS should start. Go to your web browser and check it out. http://localhost:8080

Posted in Java | Comments Off on Running JBoss Application Server


I have some projects that use Maven. Here are the steps to get maven. Go to the Maven website. There is Maven 2 and Maven 3. Get the Maven 3 download. The name of the download is the following:


If you are using Windows, you can download the version with the zip extension. Download it and unpack it on your local drive. Now add it to your path.

  • Linux (bash)
    export PATH=<Maven_home_directory>/bin
  • Windows
    set PATH=<Maven_home_directory>/bin;%path%

Now test it with the following command:

mvn -version

You should see version output similar to the following:

brian@rt13:~$ mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
Maven home: /home/brian/pkg/apache-maven-3.0.4
Java version: 1.6.0_18, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8

You now have Maven working.

Posted in Java | Comments Off on Maven

Changed comment policy

In order to comment, you have to be registered now. I thought the re-Captcha would cut out spam comments, but either there are good re-Captcha crackers out there, or a lot of people looking for trackback links. I am assuming trackback is the correct term. I am also not sure if WordPress is protecting against cross site scripting attacks as it seems to allow all html characters.

I have still been hacking a lot of Java EE stuff and I hope to post more.

Posted in Uncategorized | Comments Off on Changed comment policy

Some code would be nice!

We shall see if this turns to code.

   public class Hello {
      public static void main(String[] args) {
        System.out.println("Hello World!");
    class Example
      def example(arg1)
        return "Hello: " + arg1.to_s
#include <stdio.h>
int main(void) {
    printf("Hello World\n");
    return 0;
Posted in Uncategorized | Comments Off on Some code would be nice!

Using Flex SDK on Linux

I just ran into a great post for integrating the Flex SDK with Eclipse. Adobe makes a free software version of the Flex SDK. When you look around for getting started with Flex Builder, just about everything points to Flex Builder, which isn’t available for GNU/Linux anymore. It is built on top of Eclipse, so I don’t know why adobe did this, but it is just one more reason to use free software tools that some vendor can’t jerk you in their direction. Springsource has some great projects working with the Flex SDK.

Posted in Uncategorized | Comments Off on Using Flex SDK on Linux

Detachable Models with Wicket (Attempt one)

Here is the Code. To run it, unzip it. You need Java and Maven. To run it and view it, just issue mvn jetty:run . Point your browser to http://localhost:8080 . You can also import it into Eclipse using File->Import->Existing Projects into Workspace and then select the directory where you unzipped it. This is built upon code created for the Wicket In Action book, although the example in the book (Chapter 4.3) for this area is just fragments that compile, yet don’t run.

The great thing about Wicket is that it stores the state on the server and can work with the back button. The bad thing about this is that the Wicket models you provide for your pages get serialized and stored in a cache. Create a successful website and you may be doomed to a lot of cache of repeated that was content fetched from the database. Wicket uses what is calls detachable models to counter this problem. This sample has the detachable model working, yet I am not sure it is doing its job. The good part is that it works and now it is just a process of seeing where the problem lies. Caching is supposed to work so that when state is saved, the objects contained in the LoadableDetachableModel are not serialized. At load time, it uses the load method. Download the code and look at the following areas.

First, I created the html for a list view.


<div wicket:id="cheeses">
<h3 wicket:id="name">Gouda</h3>
<p wicket:id="description">Gouda is a Dutch...</p>
<span wicket:id="price">$1.99</span>
<a wicket:id="add" href="#">add to cart</a>

Then I created the Index.java that corresponds to the html.


public class Index extends CheesrPage {
public Index() {

// LoadableDetachableModel<List<Cheese>>
CheeseDetach myDetach = new CheeseDetach(getDAO());
// ListView<Cheese> bound to "cheese" on html
CheeseList myCheeseList = new CheeseList("cheeses", myDetach, getCart());
// Add it to the page

The java code above creates a LoadableDetachableModel called myDetach. It uses a CheeseDAO by calling getDAO() to construct it. Then, it creates a ListView called myCheeseList passing the myDetach (LoadableDetachableModel) to it. It finally adds it to the page.

The interface for CheeseDAO extends Serializable. I had to do this so it would not
produce errors.

public interface CheeseDAO extends java.io.Serializable {
public Cheese getCheese(Long id);
public List<Cheese> getCheeses();

This is troubling. It should not produce errors if it is not trying to serialize it. Ugh! Remove the extends java.io.Serializable from the interface, recompile and watch the output as it runs. It will throw an error (or is it an exception that recovers?) complaining that it is not serializable. Ugh again!

The bonus side is that I did get an LoadableDetachableModel working for a ListView. That was a little tricky! I may be complaining about nothing. Look at the following files from the code.

  • Index.java
  • CheeseDAO.java
  • CheeseDAOImpl.java
  • CheeseDetach.java
  • CheeseList.java

These files contain the essential details. I hope to gain more insight as to whether this really is not caching.

Posted in Wicket | Comments Off on Detachable Models with Wicket (Attempt one)

Bind to your model better with Wicket!

In this post, I still follow the Wicket in Action book, yet continue with the process of breaking out the concept into one simple project. This post takes the model (Customer object) and ties it to the page using the CompoundPropertyModel<Customer> object. I use paramaterized generics (<Customer>) part for the methods, so no casting of the return value needed for our callback (onSubmit). The code for this can be downloaded as hippo03.zip from my site and imported in eclipse. To run the code, you need Maven and Java. To run it, just use mvn jetty:run and point your web browser to http://localhost:8080/

The process is as follows. We create object used for model. Set the default model using the setDefaultModel for the Index.java page which extends WebPage.

We set labels so that they will use the getters from the default model. Maybe someday Java will have properties like Pascal! First, here is the Java code in Index.java creating the Customer object (our Model of MVC). I use setDefaultModel to set the model for our page (Index.html). I don’t know exactly why it is not setModel() like it is in our form, but I am still getting the details on Wicket, so I hope to figure out why later.

customer = new Customer();
customer.getAddress().setStreet("123 Easy Street");

myModel = new CompoundPropertyModel<Customer>(customer);

firstNameLabel = new Label("firstName");
lastNameLabel = new Label("lastName");
addressLabel = new Label("address.street");

This following the html for the Labels. The labels match the attributes for the object.

<td><code>firstName in Label</code></td>
<td wicket:id="firstName"></td>
<td><code>lastName in Label</code></td>
<td wicket:id="lastName"></td>
<td><code>street.address in Label</code></td>
<td wicket:id="address.street">1234 Any Street</td>

Now, we shall add the form(myForm), passing the model as an argument to the form. At first, I thought that myForm would get the model from the Index page, but it does not, so I passed it the model as an argument for the constructor. In myForm, we first add the model, and then the fields. The attributes for the fields match the names of the attributes in the Customer object model, and therefore, the model binds them directly matches the fields directly to the object. Below, first is the java code and then the html.

The Java code (Form.java)


fnameField = new TextField<String>("firstName");

lnameField = new TextField<String>("lastName");

streetField = new TextField<String>("address.street");

Java code in Index.java

myForm = new Form1("myform",myModel);

The html (Index.html)

<tr><td>First Name</td><td><input type="text" wicket:id="firstName" /></td></tr>
<tr><td>Last Name</td><td><input type="text" wicket:id="lastName" /></td></tr>
<tr><td>Street</td><td><input type="text" wicket:id="address.street" /></td></tr>

And, when the user hits the submit button for the form, we create a callback for onSubmit behavior.

protected void onSubmit() {
Customer customer =  getModelObject();
String street = customer.getAddress().getStreet();
// Probably should use logging here!
System.out.println("Customer street is " + street);
// do something with/to the customer

As the book notes, this ties the data close to the form construction. Make an UML class diagram of your model, hand it to your html designer, and it seems that you are almost all good to go. I am sure there are still little devils running through the details, but this provides good abstraction and takes the developer away from dealing with low level http dirty work. Yet, the book notes that the referenced attributes in quotes can’t be easily refactored if need be. I find that it makes MVC really clean and look forward to more.

Posted in Wicket | Comments Off on Bind to your model better with Wicket!

OpenOffice BASE and HSQLDB in server mode

The sample database for this post can be downloaded and used with GNU/Linux. It can also be adapted to Windows and Mac.

OpenOffice Base uses hsqldb as its back end database in embedded mode. If you are a developer like me, this doesn’t normally allow you to connect other tools to the database you have created in Base. In this post, I shall explore using hsqldb in server mode. This way, you get the luxury of using Base’s interface, yet at the same time the capability to connect other tools to it such as the JBOSS tools tutorial for developing a web application to display and edit your data. If you are a PERL hacker, you can use hsqldb-ber to connect to the server. In addition, the database server is started using Maven, so your database is even extra small when you zip it, because Maven is automatically downloading the jar for when you start the database.

These are the steps to follow. First, make sure that you have Maven installed on your system and java. If you don’t, install it/them using the following command:

$ sudo apt-get install maven2
$ sudo apt-get install openjdk-6-jdk
$ sudo apt-get install openjdk-6-jre

Start the hsqldb employee database using the following command:

$ ./startdb.sh

I assume that you have Base already installed. Assuming that you do, you can open the database in Base by just double clicking the employee.odb and it will open in OpenOffice Base. When you open the database file, you can browse the tables, a sample query I created named itemsorderedby363 and a report named by the same thing. The odb file contains a setting to the database in server mode. You can see the database settings by going to Edit->Databse->Properties. You can connect other applications to the database, do development, and at the same time have the luxury of using OpenOffice Base GUI interface. The data in the database comes from JBoss Demo Employee Database, yet adds the connection to the database and uses Maven for the hsqldb jar dependency.

I really like hsqldb and its robustness for development. You can easily zip your database and transport it around from machine to machine with zero configuration.


Posted in Uncategorized | Comments Off on OpenOffice BASE and HSQLDB in server mode

Callbacks and Wicket

I don’t believe starting with Anonymous Inner Classes (AIC) is a good way to get started when doing event driven programming. For this post, I took the Cheesr application from the Wicket in Action book and removed the AICs and put them in their own classes. The end result is an Index.java and an Index.html with a visible one for one correlation between Wicket tags and the Java code. The second thing I like is that you can see in the structure of the callback classes for the event driven model. Here is the code. First, I show the Index.java, its corresponding Index.html and the three callback classes: AddCheeseCB.java, CheckoutLink.java, and CheesePageList.java. Note that in the callback classes that by providing the @Override annotation that the compiler will warn if somehow you misspell your method that overrides the default behavior that usually does nothing. You can download the whole code for this sample and import it into Eclipse using File->Import…->Existing Project into Workspace. Navigate to the directory where you unzipped zebra04.zip.

Below is the html for Index.html.

<div  wicket:id="cheeses">
<h3 wicket:id="name">Gouda</h3>
<p wicket:id="description">Gouda is a Dutch...</p>
<span wicket:id="price">$1.99</span>
<a wicket:id="add" href="#">add to cart</a>
<div wicket:id="navigator"></div>

<div id="cart">
<div wicket:id="shoppingcart"></div>
<input type="button" wicket:id="checkout" value="Check out" />

This is the corresponding Java code for Index.java. Note how “cheses”, “navigator”, “shoppingcart”, and “checkout” line up nicely between the above html wicket tags and the references in the Index.java.

PageableListView cheeses =
new CheesePageList("cheeses", getCheeses(), 4, this, getCart());

add(new PagingNavigator("navigator", cheeses));
add(new ShoppingCartPanel("shoppingcart", getCart()));
add(new CheckoutLink("checkout",getCart()));

Now time for the callback classes. Some of the generic parameters still might be off, but I think this emphasizes what you can do and how the structure works. I put the callbacks in their own package.

First is AddCheeseCB. I think rather than using the <T> parameter, I should have used what the link actually uses, which I believe is <String>, but I am a little unclear on that at them moment. If you know, let me know.

public class AddCheeseCB<T> extends Link<T> {
private Cart myCart;
private static final long serialVersionUID = 1L;

public AddCheeseCB(String id, IModel<T> model, Cart cart) {
super(id, model);
myCart = cart;

public void onClick() {
Cheese selected = (Cheese) getModelObject();

Below is the code for the CheckoutLink. Note the behavior that we are implementing is onClick and isVisible. When we construct the object for the behavior, we have to give it a reference to the cart, hence the constructor with the additional arguments. I made the default constructor private. I am not sure if this is the correct approach, but it works for now.

public class CheckoutLink extends Link<String> {
Cart myCart;
private static final long serialVersionUID = 1L;

private CheckoutLink(String id) {

public CheckoutLink(String id, Cart cart) {
myCart = cart;

public void onClick() {
setResponsePage(new CheckOut());


public boolean isVisible() {
return !myCart.getCheeses().isEmpty();

Now the code for the PageableListView. I believe I specified the generic parameter <Cheese> correctly on this one.

public class CheesePageList extends PageableListView<Cheese> {
private Cart myCart;
private Index myIndex;
private static final long serialVersionUID = 1L;

public CheesePageList(String id,
IModel<? extends List<? extends Cheese>> model, int rowsPerPage) {
super(id, model, rowsPerPage);

public CheesePageList(String id,
List<Cheese> list, int rowsPerPage,
Index index, Cart cart) {
super(id, list, rowsPerPage);
myIndex = index;
myCart = cart;

protected void populateItem(ListItem<Cheese> item) {
Cheese cheese =  item.getModelObject();
item.add(new Label("name", cheese.getName()));
item.add(new Label("description", cheese.getDescription()));
item.add(new Label("price", "$" + cheese.getPrice()));

Cart myCart = myIndex.getCart();

// Create a real callback rather than an anonymous inner class!
AddCheeseCB myAddCheese = new AddCheeseCB("add", item.getModel(), myCart);



Download it and try it out. In order to launch it, all you have to do is have Maven installed and execute mvn jetty:run. Wicket is looking like it provides a good clean approach to developing Web Applications, but there is still more to explore, especially with the model that I wrote about in the last post.

Posted in Wicket | 3 Comments