I have a Struts (1.3.8) application that I'd like to convert to Tapestry 5. There will probably not be time to do the whole conversion in one fell swoop. I'd like to deliver new functionality in Tapestry and convert existing Struts / JSPs as time permits. Has anyone attempted something like this? Can Struts and Tapestry co-exist?
Without ever using Tapestry, I'd say that any two frameworks should be able to co-exist because in the web.xml
you define how the urls map to servlets/filters. For example, in Wicket there is a filter which checks for Wicket classes that implement the request handler. If nothing matches, the request is passed up the chain. This would allow you to continue to use Struts for certain actions.
If you have some URLs that you want to preserve, you can just change the Struts action to forward to the new internal URL; eventually all your struts actions will be, essentially, url-rewriting actions, and you can just rip out struts and replace it with a url re-writing filter.
If none of your new URLs will conflict with your old urls, then there is nothing difficult to do. Just set up the new framework and its request handlers. When a struts action is encountered (/doSomething.do
) the Struts ActionServlet
will dispatch the request to the action. In the struts-config.xml
you can forward to the right place, either a JSP or a tile or a Tapestry URL. I imagine there is a way, in Tapestry, to forward to an arbitrary url after you're done processing a request; just forward to a Struts action if you need to.
The one sticky problem I can foresee is if Struts and Tapestry have conflicting requirements for third-party libs. If that doesn't work you might be seriously out of luck for any kind of easy migration.
If you did Struts the way most people do it, you probably have all of your Struts urls starting with /action or ending with .do. As Mr. Shiny and New pointed out, that means you can filter different URLs with the Tapestry filter and the Struts filter or servlet. I've used both and I would strongly recommend that you try to keep Tapestry from having to deal with Struts URLs. With Struts you can pretty much hand-code the URL so it shouldn't be a problem to link to Tapestry pages, but if you want Tapestry to link back to Struts URLs you may have trouble using it the standard way. Ideally, you can split off a portion of your app (like internal admin functions) and have them be completely independent.
I did this once. I had to right a bridge between the sessions for the two frameworks since they use there own constants/prefixes for this. We did a gradual switch over from a legacy app to a T5 app. We just used the web.xml to point struts requests at struts and T5 requests would be picked up by the T5 filter. I think you can even configure the T5 filter to ignore certain urls.
We also used the tuckey URLRewrite filter to control were individual requests went, this way a page could be struts one day and T5 the next and the url would remain constant (this is useful if your struts app is live and people may have bookmarked it)
I'll read through the code (I have it archived somewhere) and post back more if I spot any gotchas.
Good luck.