File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts2 Action/OGNL in SiteMesh decorator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Action/OGNL in SiteMesh decorator" Watch "Struts2 Action/OGNL in SiteMesh decorator" New topic

Struts2 Action/OGNL in SiteMesh decorator

Raigedas Lietuvis

Joined: Oct 31, 2009
Posts: 16

while reading books, examples i have found only "Hello World" examples, but now i need to start a project with "Real World" scenario.
there is a description of a problem that i want so solve:
  • every page should have the same navigational menu
  • the menu is dynamic, fetched from DB
  • i want to construct menu in S2 Action or Interceptor

  • i choose SiteMesh for templating. i have created a SimeMesh decorator and try to use OGNL or S2 tags (yes, i have included S2 taglib page directive) in it but none of them works.
    i looked at this:
    and now it seems logical that i can not use OGNL or S2 tags in SimeMesh decorators - they are never executed. only originally requested resource gets executed (the one referred as <decorator:body />), then the result is handed to SiteMesh Filter.. then i have a question - what is the point of using SiteMesh if it can only add some static information?

    but then i read this:
    and i see include JSP directives in decorator... and i don't understand, how can they be processed. i can think of only one case - SM filter uses dispatcher to forward... please explain...

    please point me correct way to implement what i am trying to do.

    thank you

    Raigedas Lietuvis

    Joined: Oct 31, 2009
    Posts: 16
    i have found out that Struts2 tags actually are processed in the SiteMesh decorators.

    the problem is that ValueStack seems to be unaccessible. for example, if originally requested Action contains "message" property, then i am able to see it in main JSP (that referred by <decorator:body/>) using:

    but not in decorator...
    Raigedas Lietuvis

    Joined: Oct 31, 2009
    Posts: 16
    i have managed to make it work.

    for those who may be strugling with Struts2-SiteMesh integration, there i provide some guideslines:

    1. make sure that you declare Filters in web.xml in this order: first there must be a ActionContextCleanUp Struts2 filter, then SiteMeshFilter and lastly Struts2. (i provided my web.xml below)
    2. sitemesh filter mapping may need additional dispatchers: FORWARD, INCLUDE. default is only REQUEST. (i provided my web.xml below)
    3. you may need to add library struts2-sitemesh-plugin-*.jar which comes bundled with struts2.

    my web.xml:

    by the way, it looks that in new version of Struts2, com.opensymphony.sitemesh.webapp.SiteMeshFilter is changed with, and org.apache.struts2.dispatcher.FilterDispatcher with

    good luck
    I agree. Here's the link:
    subject: Struts2 Action/OGNL in SiteMesh decorator
    It's not a secret anymore!