Friday, November 21, 2008

My First Web Application

Wicket is a framework for creating Java-based web applications. It allows for separation of markup (HTML) from coding (Java). It also automatically manages server-side states.

As an exercise in learning Wicket, I created a simple stack web application. Users can input text and push that text onto a stack; they can also pop elements off of the stack, as well as clear the entire stack. The web page displays the current contents of the stack after each action. Each user gets their own session, so they are using separate instances of the application, with their own copy of their stack.


Method 1

To practice using the different features of Wicket, I implemented two different solutions to this problem. In the first method, I use a DataView to populate a table that displays the contents of the stack. The DataView gets its data from a List which reflects the contents of the stack; every time the stack is modified, the List is updated. For example, when something is pushed onto the stack, that same object is also added to the beginning of the List (so that, on the webpage, new elements appear at the top of the table). One issue I had with this method was that the table doesn't actually display the contents of the stack directly; it displays the contents of a List which reflects the contents of the stack.

Method 2

For the second method, I used a ListView to populate a table in a Panel, and I attached the Panel to the main webpage. I also added a method to the Stack class to return Stack.elements, so that the ListView can get its data directly from the stack. On the webpage, new elements appear at the bottom of the table because in the Stack class, new elements are added to the end of the elements List.

Questions

I learned a lot about Wicket from this exercise, especially from creating tests for the application. I wonder about testing practices for web applications, however. I tested that components rendered, that they displayed what they were supposed to display, and that the data objects behind the components (the models) held the correct data. That seems like a lot of testing for such a simple web application. I wasn't sure how to test the data behind the DataView, because DataViews use DataProvider objects (which are not Model objects), and I am not sure what to do with those. I also wasn't sure how to test that different users actually get different sessions, or if that is even necessary to test.

Overall, Wicket is a powerful and relatively simple to use framework for creating web applications, and I look forward to utilizing its technology in the next iteration of our DueDates project.

No comments: