DoTaL

My repository for development tidbits, and a few personal anecdotes

Archive for May, 2007

A fun afternoon in the rain

Posted by doubleA on May 24, 2007

Well, yesterday was an eventful bike commute. With the Elephant Rock ride and the Triple Bypass on the horizon, I had to get more rides in. One easy way is to commute to the light rail station, which is a 22 mile round trip from the house.

Yesterday, I decided to ride even though the weather forecast was for heavy rain in the afternoon. It was Wednesday, I hadn’t ridden since Saturday, and by golly I was going to ride.

Me and my trusty NoFlex (A vintage ProFlex that has been modified to be fully rigid) left the house and had a beautiful cool morning ride to the station. Around 2PM the rain came in and it was raining quite heavily. I decided to leave work a little early, so by 4:40PM I was at the light rail station.

There I was with me, my now soaked bike, and a light rain jacket. No sweat because once you get wet, you can’t really get any wetter. At least that’s what I always tell myself. I get bundled up, turn on the iPod and head out into the rain.

I can see some drivers giving me that look of “You must be crazy to be riding your bike in this”. And yes, I am a bit crazy, but I need the miles.

I’m tooling along, making good speed with the wind and rain directly in my face when I see a little blue car flash by. “Hey, that’s my wife!!” I wave to her as she passes me. She then pulls into the next parking lot so I stop and say hi. Of course, she is a little concerned with me riding in the rain and offers to take me home in the car after picking the boys up from daycare.

But I’m committed to this ride and I’m already soaked, so I politely decline the offer and make my way to the left turn on Monarch and the hill. The rain begins to let up and I’m just left with my soaked slacks, soaked shoes, cozy rain jacket, and my iPod spitting out The Killers, Breaking Benjamin, and Donavan Frankenreiter. Hey, this has actually been kind of fun and it’s too bad that the trip is over when I reach the house.

22 miles down for the day and one set of very wet clothes, but boy am I in a good mood. It’s amazing how a short little bike ride can put you in a good mood even when you have to deal with rain and more rain.

I’ll have to saddle up again on Friday and see what the weather brings. Knowing me, it will be wind and rain, but I can make that into an enjoyable ride.

Posted in Bikes | Leave a Comment »

Wicket models inside of ListView

Posted by doubleA on May 16, 2007

I have been using Wicket for about 6 months now and the Model concept still confuses me from time to time. For all of my repeating views, I had been using ListView for it’s simplicity (until I recently found out that DefaultDataTable is better all around). For a ListView, which is still useful depending on the situation, you have to determine how to populate the data for your ListItem within the populateItem method.

For simplicity and ease of use, my first approach had always been something like:

  1. listView = new ListView("domainObj.interestsAsList") {

  2.     	protected void populateItem(final ListItem item) {

  3.     		final Interest interest = (Interest)item.getModelObject();

  4.     		item.setModel(new CompoundPropertyModel(interest));

  5.     			

  6.     		item.add(new Label("interestType.name"));

  7.     		item.add(new Label("productType.name"));

  8.     		item.add(new Label("value"));

  9.     		item.add(new Label("startDate"));

  10.     		item.add(new Label("endDate"));

  11.     	}

  12. };

  13. add(listView);

The key line of code is the item.setModel(…). This code sets a compoundProperyModel on the ListItem which allows me to simply using the familar Wicket property matching for the labels that are added to the ListItem. The resulting code is very simple and clean because I can create my labels with just a name and Wicket takes care of calling the proper getter based on the label name.

This worked well, but then I was poking around in AppFuseLight and found another technique that does not use the property matching. The same example as above would be written as:


listView = new ListView("domainObj.interestsAsList") {
protected void populateItem(final ListItem item) {
final Interest interest = (Interest)item.getModelObject();

item.add(new Label("interestType.value", interest.getInterestType().getValue() ));
item.add(new Label("productType.value", interest.getProductType().getValue() ));
item.add(new Label("value", interest.getValue() ));
item.add(new Label("dateEffective", interest.getDateEffective()+""));
item.add(new Label("dateExpiry", interest.getDateExpiry()+""));
}
};
add(listView);

This new code is a bit more verbose in that you have to explicitly set the values for each label. However, there is one big advantage to this approach. The wicket id of your label in the html is independent of the methods for the object being displayed. Also, it’s easier to find errors when the API changes because you are using Java code instead of the property match strings.

I have now converted all of my ListViews to use the new approach that uses explicit setting of the label values because I really like the extra layer of abstraction between the object API and the HTML wicket:id values. This abstraction does create more typing and more code, but I think the tradeoff is worthwhile.

But, for an even better repeater solutions, see the DataTable and DefaultDataTable. These objects have more Java code, but there is only a single

line in the html, and since I’m a horrible html developer, I really like this idea. Wicket builds the entire table, and you can build a simple set of styles to control the formatting of the table. I’ll save the details of this for a later post though.

Posted in Java Development, Maven, Wicket | 4 Comments »