Vita Rara: A Life Uncommon

Using a Conversation Scope in Struts 2

Categories: | | |

What is a conversation scope?

A conversation scope fits between a Session scope and a Request scope in J2EE terms. An object in a session is specific to a particular user of a web app. If you place an object in the users session it will be available on every page hit the user makes.

A conversation scope defines a long lived set of data that is specific to a process, such as configuring a product, or filling out a customers personal and credit information. It differs from a session scope in that one user should be able to have multiple of th same type of conversation at the same time. You might actually have to help more than one customer at a time, or configure multiple products, one on each tab in your web browser.

Mark's Struts 2 Cookbook

Categories: | |

Struts 2 is the new version of Struts, under development at the Apache Group. It is based on WebWork 2, and has many modern web framework features, like user interface tags, type conversion, and validation. Struts 2 is highly flexible and extensible.

In this cookbook you will find HOWTO guides, and recipes for common scenarios in Struts 2.

Updating a List of Domain Entities in Struts 2

Categories: | | |

I've been working on Quadran a lot, and I'm creating pages for editing lists of entities. The CRUD example from the Struts 2 Showcase application does this in a very simple manner. It recreates all of the entities every time you update the list. That's fine for an example but unusable in real life.

In real life we have to present entities from our database and then put the values back into the same entities, and update our database. We can't just re-create them.

The Entity

So, we'll start with a simple domain object and assume that we're using something like JPA or Hibernate to persist it via a Data Access Object (DAO), and that it contains a property called "id".

Don't Swallow Exceptions

Categories: |

Over the past two days I've been trouble shooting an application for a client. It's an old Java server application based on the Enhydra Framework and EJB 1.1. It's old.

I had most everything working but something in the system was throwing an exception that the code was swallowing and just display a page that said an exception had been thrown. No log message, no stack trace, nothing. Don't ever do this. If you don't have a system wide means of handling exceptions at least put in an e.printStackTrace(). It's the least you can do.

Eventually we had to go to the vendor, who no longer really supports the application, and have them add the e.printStackTrace() statement so we could debug the application. One line was all it took to fix the issue.

MacBook Pro Core 2 Duo

Categories: | |

I picked up a new MacBook Pro (MBP) Core 2 Duo on Friday. This is a replacement for my iBook G4 1.3GHz I purchased in the fall of '04. This is my third Apple laptop, and my first professional model. My other one was an iBook G3 700MHz model.

I spent most of Saturday moving into and getting comfortable with the MBP. This is my fourth OS X migration since switching to a Mac. All in all they have gone impressively well, and this one was just more of the same. Boot the Mac for the first time, hook the firewire cable to the old machine and wait. When it's done it's your machine, with all of your files, settings, applications, etc. Apple has really made the process of moving from machine to machine a painless exercise.

Wool Gathering

Categories: | | | | |

Sometimes you stumble upon something that takes you back in time. In past times this would frequently occur in an attic, or old closet that someone was cleaning out. For me this happens when I change computers. I just got a new laptop, and I'm moving into it, after migrating all of my files over.

In this process I happened on an old QuickTime movie I made with photos from the first year of having my Canon Digital Rebel. Take a look (10MB). I thought I had posted it on this site, but apparently I hadn't. This video covers Septmber 2003 to September 2004.

JBoss 4, EJB 3 Entities (JPA), and Spring

Categories: | | | | |

Over the last week or so I have been working on getting JBoss, JPA and Spring working together. When I wrote my previous entry I thought I had everything working. Well, up to that point I had not tried to save a record to the database. When I tried to do that nothing happened. This lead to a long debugging process that felt more like a hopeless goose chase at times. With the help of Costin Leau on the Spring forum I finally got it working, but it was quite the trial. Not many people have attempted to get this combination working. One of the things that complicated my setup is that my data access objects are a descendant of the JpaDaoSupport class provided in the Spring framework.

JBoss 4, JPA, @PrePersist and Primary Key Generation

Categories: | |

JBoss 4, JPA, @PrePersist and Primary Key Generation

In a past project I started using globally unique ID's (GUID) using XDoclet. I really like this methodology and planned on using it in Quadran.

So, I wrote my classes and was generating the ID's in the persist method of my data access objects (DAO). This didn't work very well, because when my persist would cascade the dependent objects did not have their ID's set, and Hibernate, which is JBoss uses to implement JPA, would throw an exception.

So, to work around this I started traversing the graph of objects in my business classes and setting the ID's before I handed them to the DAO's to be persisted. This was ugly, so I went in search of a better solution.

Quadran Update

Categories: | | | | |

This has been a very frustrating week. All in all I worked on working. I'm fried. I'm going for ice cream.

Got JBoss, Java Persistance API, Spring and Webwork Playing Nice

Over the past few weeks I've coded the data layer of Quadran using EJB3 (JPA) and making data access object that subclass from Springs JpaDaoSupport class. Coding all of this and getting it deployed on JBoss was fairly straight forward. The interesting part came when I tried to instantiate the DAO's from Spring and inject the EntityManager instance. That was fun. Stay tuned for a HOWTO in the near future.

I also got WebWork mixed into this all. That was actually quite easy. Getting JBoss and Spring to play nicely was the hard part.

Eclipse: Not so Stable

Categories: | |

My experiment with Eclipse isn't going very well. I did an upgrade to 3.2, which apparently hopelessly corrupted my workspace, or at least that's all I can conclude based on the evidence. I say that because I'm obviously not an Eclipse expert. My diagnosis is based on the fact that a deletion of the workspace and a re-import of the project I was working on from the file system fixed the issue.

Today, Eclipse ran out of memory and has somehow corrupted its environment such that the Java Editor is hopelessly confused, and has placed error warnings, x's, along in a seemingly random pattern in almost all of my files.