• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 Action/OGNL in SiteMesh decorator

 
Raigedas Lietuvis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

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:
    http://www.opensymphony.com/sitemesh/flow.html
    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:
    http://www.opensymphony.com/sitemesh/decorators.html
    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
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter, and org.apache.struts2.dispatcher.FilterDispatcher with org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter.

    good luck
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic