views:

688

answers:

2

Hi,

I'm trying to configure sitemesh to only take effect for a certain subset of action mappings in my Struts 2 application.

Say for example, I have the following struts.xml snippet:

<package name="default" namespace="/" extends="struts-default">
  <action name="showForm">
    <result>/view/form.jsp</result>
  </action>
</package>
<package name="widgets" namespace="/widgets" extends="struts-default">
  <action name="showForm">
    <result>/view/form.jsp</result>
  </action>
</package>

I would like the output of "/showForm.action" to be decorated by SiteMesh but for "/widgets/showForm.action" to be returned empty instead. The critical part here is that I want the JSP file to be reused by both action mappings.

But try as I might, I can't seem to get SiteMesh's tag to recognize a mapping. I have to specify the file "/view/form.jsp" to be excluded instead and that means I won't be able to reuse the JSP file.

Is there any way I can get around this?

I'm using Struts 2.0.14.

Thanks, Wong

+1  A: 

You will find a good explanation of using SiteMesh here.

and Also on the Apache website here.

Hope this helps.

Kevin Boyd
Problem is, those links are basically telling me the same thing: that I can add an exclusion as long as the excluded object is an actual file, e.g. /images/hello.gif or /view/hello.jsp.What I want to exclude is the output from the Struts 2 mapping itself, i.e. include "/hello.action" but exclude "/widgets/hello.action".
feicipet
+1  A: 

Same answer as for http://stackoverflow.com/questions/619699/using-sitemesh-with-requestdispatchers-forward. You can change the way the sitemesh filter is mapped to incoming requests.

I think you'd want:

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <servlet-name>MyServlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
stevedbrown
Thanks, will try this out first.
feicipet