tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pawel Kozlowski <pkozlow...@amadeus.com>
Subject Re: how to detect when an attribute value is not found
Date Fri, 17 Oct 2008 07:47:51 GMT
Hi All,

Antonio <antonio.petrelli@gmail.com> wrote on 17/10/2008 09:25:08:


> Now I understand: you want to intercept when a Tiles attribute is
> filled with a non-existent resource.
> Well, I suppose it's hard to do, since everything is related to:
> RequestDispatcher.include
> and
> PageContext.include
> I suppose that these two methods do not throw exception if the
> resource is not found, so... I really don't know how to do it!

Well, I was struggling with the same problem for quite some time. 

The only solution I was able to employ is to create custom wrapped 
response and pass this wrapped response to the include method.

The custom response is detecting if getWriter() or getOutputStream() was 
called and by experience it means that the target resource is found. I've 
tested this with different versions of Tomcat and Weblogic. 

It is a shame that there is no standard method in J2EE web container for 
detecting this and I've found implementations of different containers to 
vary when it comes to including non-existing resource. 

The example code of a wrapper could look like this:

public class JSPIncludeResponseWrapper extends HttpServletResponseWrapper 
{

        private boolean isGetWrapperCalled = false;

        public JSPIncludeResponseWrapper(HttpServletResponse response) {
                super(response);
        }

        public PrintWriter getWriter() throws IOException {
                // Indicate getWriter() is called, meaning requested "JSP 
include"
                // exists
                this.isGetWrapperCalled = true;
                return super.getWriter();
        }

        public ServletOutputStream getOutputStream() throws IOException {
                this.isGetWrapperCalled = true;
                return super.getOutputStream();
        }

        public boolean isJSPSucessfulyIncluded() {
                return isGetWrapperCalled;
        }
}

Now, I don't know if you can control calls to include so I don't know if 
this method will work for you.

HTH,
Pawel Kozlowski


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message