Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have taken over development of a JSP/Struts application. Right now it's a bit of a mess, and I'm finding the JSP pages with Struts tags to be insanely verbose. Has anyone migrated a Struts application to Groovy/Grails? Can it be done incrementally, page by page?

@4bu3li: I was thinking of replacing the JSPs one by one with Groovy HTML builder code. IMO struts tags are a masterpiece of verbosity and obfuscation, and I'm tired of matching open and close tags. Right now the team is just me and one other guy, and I know Groovy better than I know JSPs and Struts. We are reworking the entire site, so it's all going to be rewritten somehow. But I can't stop maintenance, so I need to incrementally rewrite it page by page. Could I just start reworking Struts action methods to return Groovy-generated content?

share|improve this question
    
If it was small, it could be manageable. But if it was small, you wouldn't be asking this. –  Eric Wilson May 12 '11 at 16:36
    
Is it Struts 1 or Struts 2? Because they are almost entirely different beasts (Struts 2 used to be called WebWork). –  Behrang Jun 9 '11 at 17:46
    
@Kevin, it was already a while since you have posted this message. Have you succeed in converting the app? Maybe you have already shared your experience somehow via blogs or other posts...? I'm asking while I may have a similar project ahead. Thanks. –  Dime Mar 14 '12 at 15:25
1  
@Dime: The site is currently split into two web apps: old struts app, and new Grails app. They share the database and web context. The old functionality is being reimplemented in Grails page by page. I just installed the HAML plugin and like it a lot. –  kevin cline Mar 14 '12 at 15:39
add comment

2 Answers

up vote 3 down vote accepted
+50

I haven't used Struts for ages, but Struts by default can render Velocity markup, FreeMarker, as well as JSP (maybe other formats too).

For example, to render FreeMarker pages, your action definitions would look like this:

<action name="test" class="com.acme.TestAction">
    <result name="success" type="freemarker">test-success.ftl</result>
</action>

I assume you should be able to use a custom type to render GSP or builder code.

UPDATE:

Here it is explained how to create Struts 2 actions using Groovy.

share|improve this answer
    
@Behrand: Using Groovy HtmlBuilder, the rendering would be done by the Groovy code, and not by interpolating some data file. We use JSPs and velocity in Java because the corresponding Java code would be horrible. With a Groovy builder, there's no need to bring in another language. So I suppose my Actions could just write the response and return null. –  kevin cline Jun 9 '11 at 21:47
    
@Kevin, that could be possible. Also please read my updated post. –  Behrang Jun 9 '11 at 23:15
    
Great, now all I have to do is migrate from Struts 1 to Struts 2 :-) –  kevin cline Jun 10 '11 at 12:38
    
@Kevin, I didn't know you're using Struts 2. –  Behrang Jun 11 '11 at 3:17
    
I'm not. –  kevin cline Jun 11 '11 at 12:22
add comment

I'm not sure how your JSP Struts-flavored tags will be differ from Grails views.
Grails views are also about tags.

A much more important issue IMHO is the controllers themselves and your application's URLs. Basically you are going to rewrite the whole application which is going to consume a lot of time, a time you could spend on refactoring your current Struts project.

It is also worth mentioning that Grails applications tend to consume a lot of memory, I think you should think about this too.

What about your team? are they familiar with Groovy and Grails?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.