Hi guys.
I found a solution for what I need but is different to the ones you
proposed. As I told you, I've created a custom view preparer to resolve
parameters in the attribute values. What I've done is to add the
following line at the end of the parametrization process of the
attribute value:
HttpServletRequest req = (HttpServletRequest)
tilesContext.getRequest();
// Checks if the parametrized attribute value points to
an existing resource
try {
if
(req.getSession().getServletContext().getResource(attributeValue) == null) {
throw new PreparerException(attributeValue + "
not found.");
}
} catch (MalformedURLException e) {
throw new PreparerException(attributeValue + " not
found.");
}
Thanks to all anyway.
Best regards,
Dani.
Pawel Kozlowski escribió:
> Hi All,
>
> Antonio <[EMAIL PROTECTED]> 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
>
>
>
--
*Daniel Francisco Sabugal*
*Java/J2EE Developer*
PORTAL UNIVERSIA, S.A.
Ciudad Grupo Santander. Avda. de Cantabria s/n
Edif. Arrecife, planta 00.
28660 Boadilla del Monte - Madrid
Telf: (34) 91 289 59 12 - Fax: (34) 91 257 15 06
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
www.universia.es <http://www.universia.es>