Vita Rara: A Life Uncommon


Toward a Groovy'er Struts 2

Categories: | | | |

See latest update: Groovy Works

A further update is available here.

Last week I started implementing my Struts 2 actions in Groovy. After a few days I decided I liked Groovy, but I wanted more. I didn't want to have to restart my servlet container every time I recompiled a class. I just wanted to be able to edit, save, and reload in my browser.

I researched using Spring to instantiate my actions, but Spring's scripting integration only supports singletons. So, to get around this I extended the Struts 2 Spring Plugin to integrate the GroovyClassLoader. That created problems with Spring's use of AspectJ's pointcuts to support declarative transactions. (Thread on Spring forum.)

Web Page Data Models: Where do they go? Part II

Categories: | |

Well, I finally decided where they go. At least for the Quadran project. My package structure looks like this:

Creating a Struts 2 Action in Groovy

Categories: | | | |

(N.B.: For the latest on Struts 2 and Groovy see: Groovy Works)

Actions in Struts 2 are POJO's. Actions also serve the same purpose of the ActionForm from Struts 1, storing all of the data submitted by your user. Additionally Struts 2 action classes store the information you wish to display back to your user. (NB: Struts 2 also supports a ModelDriven style, where the Action does not need to store this data, but the ideas are largely the same.)

Over the course of developing a Struts 2 application you will write a lot of accessors, setThis(String in), getThat(). Personally I'm sick of writing those methods. Yes, I know Eclipse could write them for me, but I don't like Eclipse, and I haven't taken the time to learn another IDE. I like my Unix shell, maven, screen and vi (vim), thank you very much.

Look Ma' No Semi-Colons!


I was working on a script today. I've been working on converting a lot of Perl scripts to Groovy over the past week. Anyway, I just removed all of the semi-colons from a script to see what it looks like. I like it. It makes it look different than Java. Try it. You might think the same.

Gettin' Groovy With It

Categories: | | |

Well, this week after hearing about Groovy and reading a bit about it I decided to take the plunge. I've grown tired of the get's and set's in Java code. It's all boiler plate repetitive, non-expressive junk. I've been listening to the Java Posse for quite some time, and all the talk about language level support of properties got to me. I checked out the Grooy Beans page and was sold.

As a proof of concept I started out writing some integration tests first. I used that as the test bed to get Groovy working with Maven. (I'll write more about that later.) Once I had that done I converted a Struts 2 Action that employed an Action class, a Model and a Query bean (to store the users input) into a single clear concise Groovy class. Three classes became one, rose in readability and it was quick. My Action, Model and Query class had a total of about 40 setters and getters. They're all gone now.

Maven Jetty Plugin Logging Woes

Categories: | | |

My logging issues weren't completely over yesterday. I first adopted the "org.apache.commons.logging.impl.SimpleLog" method in the Jetty plugin, but this still spewed far too many lines of logging in my Struts 2 application. The major culprit was FreeMarker. It logs a tremendous amount of data. Far more than I would ever think the average non-FreeMarker developer would ever need.

So, I decided I needed to go the log4j route, so I could control the levels for the various libraries. I copied the dependencies section as explained on the jetty page. This lead to errors when parsing JSP pages and tags. Something in those dependencies introduced something strange into the Jetty runtime environment. After futzing about for a while, and sleeping on it I decided to just delete the dependencies and still try to use log4j. Lo and behold it worked. I started with the file in /src/main/resources created by the Struts 2 Maven archetype as my starting point, and now I have a finely tuned log4j setup.

Web Page Data Models: Where do they go?

Categories: | |

You have a web page that has tabular data that doesn't represent simple rows from a database. It's a field from this table, one from that, one from four joins away. It's a little bit of data from all over your data model, but the client wants it on the screen. What do you do?

In the past I used to just a SQL result set and turn it into a Collection. Nice and neat. Iterate over the collection and put the stuff onto the screen. Simple enough, back then. Now I'd like to have better control over my models, and have them be full classes, with strong typing, setters and getters, etc.

The question is where should that class reside? Is it part of the data model? Is it a business object? It's really a presentation model. It only exists to make presentation of data easier. In essence it's like a report, or an element of a report. So, where should it live?

Maven Jetty Plugin Logging

Categories: | | |

I've gotten Maven, Jetty, Spring, and JPA playing well together! I've ecstatic. Bye, bye JBoss. I don't know that I'll never run JBoss for development again, but I don't think it will be common.

Anyway, upon getting the Jetty Maven Plugin working (mvn jetty:run) it was logging too much debug information. Hitting one page ran out a 10,000 line buffer on my terminal. There was a simple quick fix though. Add a few properties to the plugin configuration in your POM file and voila, reasonable logging.

Kicking the JBoss Habit: JBoss, JPA and Spring? Or Spring and JPA?

Categories: | | | | | | |

Hi, my name's Mark and I'm a JBoss user.

Ok now everyone.... "Hi Mark."

I have been a JBoss user for many many years. It all started with the seductive siren of Enterprise Java Beans. I still have a deployed application running on 2.4.3, or something like that. (Behind a firewall, thank heavens.) Well, today I took a few more solid steps toward kicking the JBoss habit.

If you've followed this blog you'll remember that I'm working on an ERP application for a client, Quadran. Yesterday I fought with query issues and JSP reloads for hours. With JBoss it's compile, package, re-deploy, wait. Change a few characters, compile, package, re-deploy and wait! It finally got to me.

Creating a UI Component in Struts 2

Categories: | |


You have a form "element" that consists of several HTML actual elements. You'd like to create these using one Struts 2 UI tag, rather then write the HTML out everywhere it's needed.


The Struts 2 UI tag library provide a component tag, which can be used to create your own "tags" without needing to dive into the JSP tag library API. Creating a tag using the Struts 2 component tag, also allows it to directly take advantage of the Struts 2 framework, such as OGNL support, and the existing Struts 2 UI tag themes.


In this recipe we will creating an HTML control using the component tag that will display two input fields. This is a simple example, but it will show the process of creating a component, and tying it into the existing Struts 2 Xhtml theme.

Syndicate content