Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It should be possible to run the filter twice when desired #29

Open
adam-roth opened this issue Apr 16, 2014 · 1 comment
Open

It should be possible to run the filter twice when desired #29

adam-roth opened this issue Apr 16, 2014 · 1 comment

Comments

@adam-roth
Copy link

There are valid use-cases that may result in the sitemesh filter running twice (or more) in the context of a single request. One simple example of this involves using JSP pages to render HTML e-mail content. A request that dispatches such an e-mail can retrieve the rendered JSP contents as a string by including it (and wrapping the HttpServletResponse appropriately). Thus it can be desirable to have multiple runs of the sitemesh filter, one for the response that is ultimately sent to the client/browser, and one for each e-mail composed in this manner (because using sitemesh to decorate the e-mails would be extremely convenient).

I think there are a couple of simple ways to support this:

  1. Make 'filterAlreadyAppliedForRequest' protected instead of private. Doing so will allow users to subclass SiteMeshFilter and provide their own implementation that can be made to run more than once per request as desired.
  2. Instead of using the literal key of "com.opensymphony.sitemesh.APPLIED_ONCE" to flag whether or not the filter has been applied, suffix this key with something like the filter's hashCode or the current timestamp (or random number) at instantiation/init-time. That would allow a user who wants to have the filter applied twice in some scenarios to simply set up two instances of it with different filter-mappings (which can/will overlap in some cases). Neither filter would allow itself to be applied more than once per request, but both would be able to coexist side-by-side without one cancelling out the other.
@sykobee
Copy link

sykobee commented Nov 20, 2014

Whilst we are trying to remove SiteMesh from our webapps as and when we can, we ran into an issue where we forward a request, and the forward wouldn't go through SiteMesh because of the aforementioned APPLIED_ONCE flag, so we are just clearing that attribute before the forward to ensure the correct decorators are applied to the forwarded request's content.

You can't even exclude the request URL in decorators.xml because SiteMeshFilter sets APPLIED_ONCE to true before checking whether the request is excluded - these checks should be switched around:

    if (filterAlreadyAppliedForRequest(request)) { ...}
    if (!contentProcessor.handles(webAppContext)) { ... }

I guess we could create our own SiteMeshFilter impl if we really cared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants