Monday, March 12, 2007

Getting started with Struts 2 and Tiles 2

I do not recommend you using Struts 2 for any reason. For more information, read the last paragraphs of the article.

I suppose this would be a easy work for 2, 3 hours but I spend some days in it, there are little information yet on internet, so I'll try to correct this.
What I've done for you - a simple war file, it is called (edit: sorry, I lost the file), so you can use it as template, base to start. It's a some kind of HOW-TO, first steps or something when you decide to build applications on Struts 2 framework with the new Tiles 2.
Versions tath I use are struts 2.0.6, tiles 2.0.6.
In zip file you have mine project with lib included, and some jsp. What it can do? You have a one page with listing fo imputed news in application, and one page for editing them. They use actions & form beans.
I disabled some jar files beceuse I will not use their funcionality - JSF, String and Plexus.
Here is a list of more critical moments for me, where I spend a lot of time:







One of the tricks was with tiles TLD: copy tiles-core.tld from tiles-core.jar (open it with WinRAR) and extract the TLD file to WEB-INF directory, and add in web.xml
Other trick is to remove some jars: spring plugin, jsf plugin and plexus plugin. In version struts 2.0.6 they do problems.

And a little hint, Struts 2 is based on WebWorks framework, you can search with this keyword for more results in google.

If you have questions, post comments here. I'll try to update this howto with your experience.

P.S. for UTF-8 charset managment:  In version 2.0.6 there are bugs in tiles, so setting charset / encoding of page to UTF-8 is problematic. If the lastest GA release is 2.0.6 yet, please update to lastest snapshot of struts2-core, struts2-config-browser-plugin, struts2-tiles-plugin, tiles-core, tiles-api from and 
This bug is reported in;jsessionid=8E3A7086E59002AC8802744730F17487?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

EDIT: I don't know when but I have removed the archive for kickstarting :(    I searched my linux box and my desktop PC for it, but with no result...

I will strongly recommend you NOT to use any Struts framework for your new projects, cause for time I have spend with it, I have faced with a numerous number of bugs! In my case using of General Availability releases (in simple words this means it is stable enough to be used) and a lot problems go out while doing only simple things. For example with mentioned version of Struts 2, I encounter problems with outputing text strings from resource bundle - I have used the simplest usage of that tag. Later I sam that many people complained from this! Very unserious for stable version.

Other problem with the release was using the plugin which would allow me to use Struts 1 and Struts 2 together. Another dead end - this does not work. Ohhh, shit.

Later I switched to the other big framework - Sun's JSF. For a kickstart I used AppFuse. I highly recommend you to do this way - using AppFuse. Easy, high-tech, fast, feature-rich solution! Many examples come with default installation. Everything I needed.

For JSF I can tell you only good things - stable (!!!) framework, authors have thought for many programmer needs before designing the backbone of it, so many pleasant tricks expect you if you switch to it. I have found many of my workarounds I made in Struts 1, have been implemented in a clear way in JSF. And in better way than I could imagine. So the feeling of going to JSF framework was as I have replaced my old Trabant with a new spaceship.

For a conclusion, I will highly recommend using JSF in place of Struts 2 again.

No, no one give me money to tell you this :)