• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Do I have to choose only one view solution in Struts2?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Struts Folks --

I'm (very new to Struts2 but am) working on integrating Struts2 as an MVC foundation for a web app that, at the moment, just provides a set of custom taglibs and a data object layer for a team of content creators and page designers, using Hibernate-by-way-of-Spring-IOC.

The goal is to build in a templating aspect to the app, where requests to the actions, after business logic, result in template-driven output (either through Velocity or FreeMarker), or a JSP error page. In selecting Struts2, I'd thought that it'd be possible to provide support for both along with JSP, based on the selection of result types I can choose from (freemarker, velocity, default JSP, et cetera).

Using the Struts2 Starter archetype in Maven, I know I can start with this...

web.xml
...and substitute org.apache.struts2.sitemesh.FreeMarkerPageFilter or org.apache.struts2.sitemesh.VelocityPageFilter for PageFilter. But I'm not clear on how I should layer in the filters for all three, if the action's conditions could result in a different template being driven, like this:

struts.xml
Trying to direct to the native VelocityResult with PageFilter turned on results in ClassNotFound exceptions for Velocity's Context object; switching to VelocityPageFilter but directing to a default JSP result returns exceptions complaining about missing FreeMarker dependencies.

In searching JavaRanch and the web at large, I've found examples showing me that I can use Velocity or FM or JSP for view output, but nothing saying that I can (or can't, for that matter) provide support for all three, switching between results when I need to. Have I stumbled upon an implied, but not explicit, limitation of Struts2, or am I missing something painfully obvious?

Peter DiCrescenzo
peter.dicrescenzo@gartner.com
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know the overarching answer, but I think supporting both Velocity and FreeMarker is a bad idea: pick one. Better yet, pick one of the three.
 
Peter DiCrescenzo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Dave! (disclosure: I've currently only got Ian Roughley's Practical Apache Struts2 Web 2.0 Projects for a source text, but have your Apache Struts2 Web Application Development book from Packt on a wish-list. I'm delighted you're able to weigh in on this.)

The environment I'm working with will necessitate at least two - my content guys currently generate hundreds of JSPs, many of which (but nowhere near all) would be candidates for templating.

The actual templating action could drive to Velocity (or FreeMarker) only, if I absolutely have to do that - but I'd still need to provide for an "Error" result which would drive to one of the error-code JSPs we've got (300,400,500 errors etc.), and I can't preclude JSP views from additional actions that I end up authoring in Struts2.

You'd recommended using native Velocity results to Thiyagaraja Thamilvaanan last year - but is there a better approach than using the native result options in Struts2, that are still optimal for Struts2, considering what I'm trying to accomplish? Is Struts2 still an appropriate MVC framework for me to try to do this in?

-pjd
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommended Velocity only because that's what they were already trying to do--between Velocity and FreeMarker I recommend FreeMarker because of the better error reporting.

You're aware you can template using JSP, right?
 
Peter DiCrescenzo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but I'm looking to support a templating scheme like Velocity (and/or FreeMarker); again, is there a better approach than using the native result options in Struts2, that are still optimal for Struts2? Is Struts2 still an appropriate MVC framework for me to try to do this in?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like I said--I don't know. I think trying to support more than JSP plus another one is a bad idea. SiteMesh will glom together whatever you want, depending on how you're doing your templating. I have multiple JSP + FreeMarker apps together, but except for components, I've never mixed multiple technologies together, because I think it gets too confusing.
 
Peter DiCrescenzo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll work with that to start - so SiteMesh should allow me to have a Struts2 action where my result could be driven to JSPs (PageFilter) or templates (VelocityPageFilter), depending on which result I pick? What did I miss in my configuration to allow that?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea. As I've said, I don't use Velocity, and its support is not as good as the FreeMarker support. The result choice shouldn't matter as far as SiteMesh goes--as long as the filters are in the correct order (which I don't know what is), I don't know why it wouldn't work. I know people are doing SiteMesh + FreeMarker, and I'd be surprised if JSP didn't "just work".
 
reply
    Bookmark Topic Watch Topic
  • New Topic