How to Use displaytag with Struts

August 4th, 2009

I recently had the need to use displaytag with Struts and since I didn’t want to forget how I did this, I’m writing a blog about it. Although I don’t know if anyone else on the planet still uses Struts and/or displaytag, I suppose this could also be useful to someone else. I make no claims as to the validity of the code because this is not my actual code, I just typed up a simpler example with some of the more important and interesting pieces of code.

The JSP markup

I had a need for a nested table, which is actually pretty easy to do using displaytag once you figure it out. Well, here’s some code so that you won’t have to figure it out yourself.When I initially added the nested table, I was able to display the raw data, but each entry was enclosed in brackets, which I didn’t want. (It looked like this: [1234]) I had to add a decorator in order to remove the brackets and so while I was at it, I also added some other formatting to the data. Note in the nested table that I had to add a decorator attribute in order to call the Java code called MyDecorator (shown below).

<display:table name="${dtoList}" id="parent" pagesize="5" class="css_for_outer_table" sort="list"><display:column property="ssn" title="SSN" group="1" sortable="true"><display:column property="firstName" title="First Name"><display:column property="lastName" title="Last Name"><display:table name="${parent}" id="${details}" class="css_for_inner_table" decorator="com.package.name.MyDecorator "></display:table></display:column></display:column></display:column></display:table>

The Decorator

A decorator allows you to change formatting of the data so you can do things like add a dollar sign to currency or units such at “ounces” after the data. This is also helpful in changing the default formatting of the data, which in my case contained brackets around the data. There are several types of decorators available, but what I needed was the TableDecorator. More information on decorators is available at the SourceForge website at this link: http://displaytag.sourceforge.net/11/tut_decorators.html

public class MyDecorator extends TableDecorator {	// You will need to call the TableDecorator's constructor or things won't work right. public MyDecorator() {super();}// This method puts asterisks around the SSN. (A made up example, can't think of a good reason why you would do this.)public String getSsn() {MyDTO dto = (MyDTO) getCurrentRowObject();return ("*" + dto.getSsn() + "*");}// This method modifies the phone number to add an area code on the front of each one.// This is a made up example, but a real life example of where this could be used is if, say,// you had a list of phone numbers without area codes and you knew they were all in the// same area code and had a requirement to display it on the page.public String getPhoneNumber() {MyDTO dto = (MyDTO) getCurrentRowObject();ArrayList<long> phList = dto.getPhoneNumber();</long>StringBuffer result = new StringBuffer();// The space in the second .append is used to separate multiple entries in the listfor (Long ph : phList) {result.append("703 " + ph).append(" ");}return(result.toString());}}

The DTO

In order to display the data on the JSP page, I created a data transfer object that contained only the data I needed to display. The source of my data came from several different database tables, and a common way of consolidating all this information for ease of display is into a DTO. The DTO that I am showing here contains information about a person: a SSN, a first and last name, and a list of phone numbers.Disclaimer: I probably would not use a Long for a SSN or phone number in real life, but I’m using it here in order to make a point. I would probably use Strings for those, as well.

public class MyDTO {	private Long ssn; private String firstName;private String lastName;private ArrayList<long> phoneNumber;</long>public MyDTO() {this.phoneNumber = new ArrayList<long>;</long>}/* Setters and Getters for all of the member variables go here, but I have not shown them because... well, they are boring. *//* I also found it useful for my app to include the following methods for the phoneNumber */public Long getPhoneNumberByIndex(int index) {return phoneNumber.get(index);}public void setPhoneNumberByIndex(int index, Long phoneNumber) {this.phoneNumber.add(index, phoneNumber);}}

The Java code that loads up the DTO

This is a snippet of the code that I used to load the data into the DTO. When using Struts, this code resides in the action class. In reality, this would be much more complicated code because you’ll have to get the data from somewhere, like a database, but this will give you the idea.

public class MyStrutsAction extends MappingDispatchAction {	public ActionForward viewPage(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response)  throws Exception { 	// Load up DTOList<mydto> myList = new ArrayList<mydto>();</mydto></mydto>myList .setSsn(111223333);myList .setFirstName("Jane");myList .setLastName("Smith");myList .setPhoneNumberByIndex(0, 1112222);myList .setPhoneNumberByIndex(1, 3334444);myList .setPhoneNumberByIndex(2, 5556666);request.setAttribute("dtoList", myList);// Forward to the correct pageActionForward forward = mapping.findForward("viewPage");return forward;}}

Other notes about displaytag

Although it is outside the scope of my example here, I wanted to show some other interesting things that I discovered about displaytag. In my example above, the id “parent” can be used to reference the DTO fields outside of the column attributes. So, let’s say you needed to refer to the last name for some reason. You can refer to it as ${parent.lastName}. Also, if you’re using JSTL and you need that value to output to the page or otherwise used within your other tags, you can use c:out to do that. So here is an example of sending a hidden field back to the server using this idea:

<input name="myHiddenField" value="&lt;c:out value='${parent.lastName}'&gt;&lt;/input&gt;" type="hidden" />

Another important concept in displaytag is being able to get the number of the current row. You can get this by using the ‘parent’ id as we did before but in this case, you tack on an underscore and the text “rowNum”, like this: ${parent_rowNum}. The reference to the row number is called an implicit object and you can read more about this at SourceForge’s page: http://displaytag.sourceforge.net/11/tut_implicitobjects.html.The columns in a displaytag table need not be as simple as what I’ve shown here. Besides including another displaytag table within a column, you can include just about anything you like. In my code, I have included input tags, JSTL tags (e.g., c:set), and Javascript inside a display tag column. Here is a snippet of some code that I actually used, with a few pieces left out:

 <display:column title="More Complicated Column"><input id="dates_&lt;c:out value='${parent_rowNum}'&gt;&lt;/input&gt; name=" size="10" maxlength="10" value="&lt;c:out value='${parent.date}'/&gt;" type="text" /><c:set var="trigger" value="trigger_${parent_rowNum}"></c:set><img src="http://rodneyandtina.com/blog/wp-admin/%3Cc:url%20value=" id="&lt;c:out value='${trigger}' /&gt;" />" alt="Calendar" title="Calendar"/&gt;<script> 		Calendar.setup(button:"<c:out value=''/>", /* other setup here */); 	</script></display:column>

Request parameters and displaytag

If you want one of your data columns to be links to a url, you can do that by including a “url” attribute in your display:column. If you need to send a request parameter with the url, you can do this by using the paramId and paramProperty attributes. Here is an example:

<display:column property="phoneNumber" title="Phone Number" url="/viewDetails.do" paramid="phoneNumber" paramproperty="phoneNum"></display:column>

In theory, you can even have multiple request parameters, like this (although I couldn’t get this to work for my code). Note that rowNum is a predefined property, which is why there is a colon in front of it:

<display:column property="phoneNumber" title="Phone Number" url="/viewDetails.do" paramid="rowNum,phoneNumber" paramproperty=":rowNum,phoneNum"></display:column>

The method that I decided to use when I needed to send multiple request parameters was this one:

<display:column property="phoneNumber" title="Phone Number">     <a href="http://rodneyandtina.com/blog/wp-admin/%3Cc:url%20value=" viewdetails.do?name="${name}&amp;phoneNumber=${phoneNumber}"></a>" &gt;<c:out value="${phoneNumber}"></c:out></display:column>

The example above sends both the name and phone number as request parameters to the Struts action viewDetails.

Displaytag is kinda cool!

So there you have it. You can do a lot of neat things with displaytag and it’s a lot easier once someone else shows you how.

My First Solo Jazz Performance

June 16th, 2009

Tonight I performed at Twin Jazz on U Street in Washington, D.C. as part of the culmination of a jazz vocal workshop that I have been involved with for the past 8 weeks. This was my first solo jazz performance (not including a couple of open mic nights I’ve attended in the past week). The experience was incredibly fun because in addition to learn some cool jazz tunes and getting to perform them, I have also been hanging out with some fun people who enjoy jazz as much as I do. I’ll be taking the workshop again in a few weeks and I’m looking forward learning more new songs and performing again in about nine weeks.My actual performance tonight was disappointing to me. I had a complete brain freeze on the first piece and forgot an entire verse of the song. And this is a song that I knew inside and out. I had the words in front of me and couldn’t even focus enough to remember the words. It was terribly scary to complete blank out that way. Honestly, I cannot say what happened or why I blanked out that way. I didn’t feel as nervous as such a huge bobble would indicate. It was just “one of those things.” I did manage to pull myself back together and finish the song just fine.My second piece (”Cry Me a River”) went just fine. I got a little help from our instructor, who started the band at a tempo that he knew would work for me but he told me that he was going to do that while we were still in rehearsals. Finally, I sang “Desafinado” which went fine except that I chose the tempo and it was way too fast! I got a harsh lesson in what happens when I’m nervous and trying to choose a tempo. The song came out ok, but probably would have been a lot better at a slightly slower tempo (i.e., as I’d rehearsed it).In a way, all my foibles tonight turned out to be a good experience because I really learned very quickly how to keep it together when things fall apart. Amazingly, I was able to finish my second two songs with no mistakes at all (except tempo) after having totally blown the first. I also got through my very fast version of Desafinado without any major blunders — just a lot faster than I’d planned. :)I felt good as I sang and after reviewing some video, I think I sounded ok, too. But what I didn’t like was how I looked or carried myself. I feel that I really have a long way to go before I will look relaxed and professional.  It’s not just solo jazz that is the problem, though, as I don’t particularly like the way I look when I see myself on a video with Vocal Express, either. I think I just don’t like seeing myself (which is probably quite common).There were a  lot of surprises in the performances tonight of my colleagues in the workshop who were also singing. Some of them performed better than in rehearsal; some of them strangely worse than in rehearsal. It is curious how different people’s performances can be when they are put in front of an audience.I had a great time tonight. The whole night zoomed by and is somewhat a blur. I would like to keep singing jazz and trying to improve my skills. And I’m thinking that maybe I need to learn how to make up lyrics on the spot like Ella Fitzgerald. :)

My First Open Mic Experience

June 11th, 2009

Tonight I went to — and performed at — my first open mic night. It was actually not as formal as it sounds, just a piano player in a hotel with a standard crew of singers (about 15 or so in all) that get together one or two nights a week and sing to each other. I was invited to attend by one of the other singers in the jazz vocal workshop that I am taking. She invited me to “shake my nerves out” before our big performance on Monday (June 15), because I have been very tense about our upcoming performance. (It’s the culmination of the work we’ve done in our seven week workshop.)This particular open mic group gets together routinely and many of them already know each other. It was a fun group and what I was most impressed about was the support that everyone got. Everyone was given an equal opportunity to perform (one guy even read poetry to music) and everyone got applause. It was a wonderful place for newbies like me to try out their skills.The scariest part for me was singing with a musician that I had never heard before. I wasn’t sure what to expect and I worried that I wouldn’t know my songs well enough to keep going if his accompaniment didn’t sound right to me. It definitely was different singing with this piano player than with our vocal workshop instructor, but in the end, I did ok. I did miss one entrance, or at least I think so. The piano player went with me and even though he made a mistake shortly thereafter, I’m pretty sure it was I who made the mistake and that’s what messed him up. But aside from that, it was fine. (Ironically, I messed up on my easiest number.) I still got applause and it felt great.I feel ready for our performance on Monday, much more so than I did last Monday at “dress rehearsal”. My nerves just overtook me there and I was not at my best. Tonight was easy and fun, the way I imagine performing ought to be. I’d like to get to the point that every performance feels like that. I think it’s possible, but I realize that I need a lot more training — and a lot more open mic nights! — before that is going to be a reality for me.I’ve never thought of myself as a serious performer, but recently I’ve started to think that I should. Not because I’m so good, but because I think the idea of being serious precludes actually being good. I’m grateful to Courtney (the woman who invited me to the open mic night) and the other performers who have been so gracious and kind to me over the past few weeks. I have always thought of the music industry as being cutthroat and as a consequence, that performers are, as well. But tonight’s experience tells me otherwise. Not all performers are divas, loathing to share their stage with others. These folks obviously love their craft and love to share it with each other. It makes me think that possibly there is a place for me in this community, after all.

Beyond the Sea

June 6th, 2009

About the Song

The most well-known version of Beyond the Sea was recorded by Bobby Darin in 1959 for Atlantic Records. The song was originally written in French by Charles Trènet and called La Mer.

French Lyrics and Translation

A translation is provided at http://lostpedia.wikia.com/wiki/La_Mer:

La mer
The Sea
Qu’on voit danser le long des golfes clairs
That one sees dancing along the clear gulfs
A des reflets d’argent
Has silver reflections
La mer
The Sea
Des reflets changeants
Changing reflections
Sous la pluie
Under the rain

La mer
The Sea
Au ciel d’été confond
In the summer sky merge
Ses blancs moutons
Its white sheep
Avec les anges si purs
With such pure angels
La mer bergère d’azur
The sea, shepherdess of azure
Infinie
Infinite

Voyez
See
Près des étangs
Close to the ponds
Ces grands roseaux mouillés
These large wet reeds
Voyez
See?
Ces oiseaux blancs
These white birds
Et ces maisons rouillées
And these rusted houses

La mer
The Sea
Les a bercés
Has rocked them
Le long des golfes clairs
Along the clear gulfs
Et d’une chanson d’amour
And with a song of love
La mer
The Sea
A bercé mon cœur pour la vie
Has soothed my heart for life

English Lyrics

The English lyrics written by Jack Lawrence are distinctly different from the French lyrics:

Somewhere beyond the sea
Somewhere waiting for me,
My lover stands on golden sands
And watches the ships that go sailing;

Somewhere beyond the sea
He’s there watching for me,
If I could fly like birds on high,
Then straight to his arms I’d go sailing.

It’s far beyond a star
It’s near beyond the moon,
I know beyond a doubt
My heart will lead me there soon.

We’ll meet beyond the shore
We’ll kiss just as before,
Happy we’ll be beyond the sea
And never again I’ll go sailing.

Recordings available online

Here are a number of notable recordings of Beyond the Sea that I found on YouTube:

Charles Trènet – the songwriter singing La Mer in French. Note how slowly he is singing this and how different the ending is from the Darin version:
http://www.youtube.com/watch?v=fd_nopTFuZA&feature=related

http://www.youtube.com/watch?v=KHYj1-3QrrY&feature=related

Bobby Darin - the most popular version of this song ever recorded:
http://www.youtube.com/watch?v=m8OlDPqYBLw

Kevin Spacey - I think Kevin did an incredible job on this. I like it even better than Bobby Darin’s version:
http://www.youtube.com/watch?v=GbcjW9SQabc&feature=related

Wet Wet Wet - I like this version, it’s fun and has lots of energy. They even do a little George Benson-like thing in the middle:
http://www.youtube.com/watch?v=LZXjpyrv2so

Bobby Caldwell - A bit too lounge singer-ish for my tastes, but the instrumentals are cool:
http://www.youtube.com/watch?v=04l9Lls5WKc

Robbie Williams:
http://www.youtube.com/watch?v=nrxgqhrNnXg&feature=related

Celtic Woman - My pick for worst rendition of this song. I really don’t think Beyond the Sea should ever be done in a Celtic version, and especially not this slow. I find this painful to see and hear:
http://www.youtube.com/watch?v=vz_fcbKKmQA

George Benson - I am a George Benson fan, but I think he could have done more with this song. The tempo is just too slow to be interesting to me. The only good part is George’s guitar solo in the middle:
http://www.youtube.com/watch?v=qUCABheaOV8

Susan Wong - I just don’t think this one works:
http://www.youtube.com/watch?v=5GiDF1w71vo

Sandra Reemer:
http://www.youtube.com/watch?v=fSvNrpXmhOM

Graham Ko - I really like this version and I like this guy’s style:
http://www.youtube.com/watch?v=8lU0uhj9l2k

Beyond the Sea and Me

I am going to sing this piece on June 15th as the “final project” for a jazz workshop that I am taking. Beyond the Sea follows the standard AABA form commonly seen in jazz pieces. I’ll be singing it in the key of D which is quite comfortable for me. It’s not a difficult song vocally for me although it does have notes at the upper and lower limits of my range. Fortunately, it’s just a few notes and for some reason I don’t find reaching those notes difficult in this piece. I’ll be singing this song as my first piece of three and hoping that the audience will enjoy the light and happy style in which I plan to sing Beyond the Sea.

Cry Me a River

May 6th, 2009

About the Song

Wikipedia has a list over nearly 150 “selected” recordings of Cry Me a River which seems to be an indicator of its (huge) popularity. Written by Arthur Hamilton and first published in 1953, the song was made famous by Julie London in 1956 in a film called The Girl Can’t Help It. In the movie, Julie London plays herself, a jilted lover of press agent Tom Miller. The film is a must-see, if only for London’s scene where she sings her sultry version of “Cry Me a River”. This is still my favorite version of the song. I think Julie London captures the essence of the song beautifully.

To me, the song is a sad piece, but not a vengeful one. I’ve always considered the phrase “cry me a river” to be an overly dramatic metaphor, but it was pointed out to me that the song could have an entirely different tone. The sentiment, taken a few steps further, could actually border on the psychotic. An example of this interpretation is in Barbara Streisand’s performance on the Dinah Shore show in 1963 (see below). I think Ms. Streisand’s performance is incredible, though a little disturbing.

Recordings available online

Here are a number of notable recordings of Cry Me a River that I found on YouTube:

Julie London — This is the definitive recording in my book (note that this video is straight from The Girl Can’t Help It so don’t watch it if you plan to see the movie first:

http://www.youtube.com/watch?v=141HmTUCfsg

Julie London several years later in 1964 - It’s interesting to compare this version to her earlier version:

http://www.youtube.com/watch?v=DXg6UB9Qk0o&NR=1

Susan Boyle:

http://www.youtube.com/watch?v=Wxy8bLzsCfM 

Barbara Streisand from May 1963 on the Dinah Shore Show:

http://www.youtube.com/watch?v=2TA6LQmP0ec

 Mari Wilson — a “sweeter” and slower version than London or Streisand:

http://www.youtube.com/watch?v=ghfxKyDznQU&feature=related

Diana Krall — She has a great voice, a great band, and this is mostly a great arrangement, but I’m not a fan of her vocal interpretation here:

http://www.youtube.com/watch?v=F9y1vGxPVAA&feature=related

Joe Cocker — Gets the award for the most unique arrangement by far!:

http://www.youtube.com/watch?v=SMwXPueu-RM&feature=related 

Ella Fitzgerald and Joe Pass:

http://www.youtube.com/watch?v=jAoABuJS1MA

Cry Me a River and Me

I am going to sing this piece on June 15th as the “final project” for a jazz workshop that I am taking. Cry Me a River follows the standard AABA form commonly seen in jazz pieces. My vision for this piece is slow, but not too slow, and the key I’ve chosen is A minor. Despite a low A (which is a bit lower than I prefer) that pops up in several places in this key, it is a fairly comfortable key for me. I could probably sing this song one or two half steps higher, but A minor puts the majority of the notes in the most comfortable part of my range. I also think that female jazz vocalists sound better in lower keys, so I’m trying to keep the key as low as possible. This is a great song and I’m hopeful that the audience will enjoy it as much as I do.