feicipet
feicipet

Reputation: 954

Configuring SiteMesh for specific action mappings in Struts 2?

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

Upvotes: 0

Views: 2105

Answers (1)

stevedbrown
stevedbrown

Reputation: 8934

Same answer as for Using SiteMesh with RequestDispatcher's 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>

Upvotes: 1

Related Questions