Wednesday, February 6, 2008

Getting started with Struts 2 and Tiles 2


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 struts2+tiles2-blank-2.0.6.zip, 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:
web.xml
struts.xml
tiles.xml
struts.properties
stdLayout.jsp
listNews.jsp
editNews.jsp
NewsAction.java
News.java

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 http://people.apache.org/builds/jakarta-struts/nightlies/2.0.x/ and http://people.apache.org/maven-snapshot-repository/org/apache/struts/tiles/tiles-core/2.0-488434-SNAPSHOT/ 
This bug is reported in https://issues.apache.org/struts/browse/WW-1724;jsessionid=8E3A7086E59002AC8802744730F17487?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel