Welcome to my blog.

Sunday, November 23, 2008

My first Wicket Web Application

| |

There are many frameworks available today for creating dynamic web applications, some of which are extremely complicated and hard to use. Wicket is one of the few, easy to use tools out there that works well with Java programming. What makes Wicket different from most other web application tools is that it effectively separates the logic of the actual program from the simple HTML markup of a web page.

This week I set out to learn how to use Wicket in order to create a small web application for a simple stack Java program. With this program, a user can push items onto a stack, pop items from a stack, as well as clear the entire stack. Although the functionality of the program was quite simple, creating a web application for it did turn out to be more of a challenge.

Final Distribution Package for the Web App: stack-wicket-wolfft-1.0.1123.zip

Picture 1
final view of the stack web application

THE DEVELOPMENT PROCESS:
After reading some of the chapters of Wicket in Action as well as reviewing some actual examples provided by Dr. Johnson,  I started to grasp some of the basic principles of using Wicket. To my surprise creating an HTML page to interface a Java program is an extremely easy and clean process. Since there is no logic in the markup, the HTML page is left as simple as possible, and can be stylized and viewed all on its own.

On the other hand, creating a Java application that works with this HTML page is a bit more complicated. I wanted to create a stack application that would employ the use of forms, basic text output, as well as table output. In addition, I wanted to give each user of the application their own session in order to store their personal stack object and data. Luckily with Wicket, this task was not too daunting either. 

To do it all, I had to create an application class, then a page class, and then finally a sessions class. All of these components essentially run together to create the stack web application. Creating the page class was probably the most challenging out of all the classes since all sorts of different HTML elements were being updated on the one page at once. 

Another thing worth mentioning is the applications use of Jetty, a web server implementation that enables Java applications to run on a server. This was used to create a fully-working web application, though I more or less just reused code to get it to run.

DEVELOPMENT PROBLEMS:
I had a good time creating this stack application. I get real satisfaction from creating something that anyone can go out and use without having to run through a console. However, I did run into some small problems while developing it all. For one I had to figure out how to alert the user when they were trying to pop an empty stack. I fixed this by creating an error response text field in the page that would alert the user if they were popping an empty stack. Something else I could have done with this was only make the pop button visible when there were items in the stack.

Something else that I ran into was that initially the stack was presented in the table in list form, not stack form. This means the first item pushed was always the top item in the table. The way I like to thing of stack is the opposite of this and I wanted to make that clear on the page. I ended up creating a method in the Stack class that would put the stack in the right visual order right before updating the data to to table. It worked out quite nicely.

Also, one of the funny errors I kept getting was from CheckStyle on the basic Stack package classes. It simply stated:
Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'EmptyStackException'.
This was extremely confusing because I did not even alter the classes that the error was from. I was really stumped with this one and searched all over to try and figure it out. The problem ended up stemming from the build.xml file, which was not compiling all the classes, namely the EmptyStackException class. It was something small that I missed and when it was fixed it all worked nicely together.

LESSONS LEARNED
Creating this simple web app was more challenging than I initially anticipated. I spent a lot of time looking at the Wicket examples, trying to figure out the best way to create the application page, and still it wasn't working for me. Yet, now that it is all done, I feel I have a fairly good understanding of the Wicket framework. All the work spent on figuring out different ways to do things resulted in more knowledge of how things work. I do feel comfortable with Wicket and I know I will be using it in the future to create even more extensive web applications.

0 comments: