Skip to main content

[webtier] ResourceHandler[Wrapper] in JSF 2.0

8 replies [Last post]
Anonymous

Hi,

I have a (hopefully basic) question about implementing and instantiating a
ResourceHandlerWrapper in JSF 2.0.

How can I wrap in a ResourceHandlerWrapper any "underlying" ResourceHandler?

I'm working on a library which would need to override some of the behavior
defined by the ResourceHandler, but I would like to be kind with the
specific JSF 2.0 flavor my library may be going to run on.

In example, I would like to avoid to make a direct reference to the
com.sun.faces.application.resource.ResourceHandlerImpl in my
ResourceHandlerWrapper implementation. Also, if a third-party library is
actually wrapping any "official" ResourceHandler implementation, I would
like to avoid breaking things by letting my library directly wrap the
official handler, and instead wrap the third-party one.

Is there any way to do this?

I attempted looking for a reply to this at the JSF 2.0 specifications as
well as to the JSF-ri documents and sources, but I was unable to find any.

Thank you in advance,

Giampaolo

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joel Weight

Agreed that it could be more clear, but I was looking at the javadoc, not
the spec. I finally found the info in Ed Burns book page 361.

One gotcha I found was that if you want to override createResource, then you
also must override handleResourceRequest, because the wrapper implementation
of handleResourceRequest delegates to the wrapped instance, which calls its
own createResource instead of the one you implemented in your extension of
ResourceHandlerWrapper.

Good luck,

Joel
http://digitaljoel.nerd-herders.com

On Fri, Sep 24, 2010 at 10:36 AM, Giampaolo Tomassoni <
Giampaolo@tomassoni.biz> wrote:

> > I think you can do that by adding a constructor that takes a
> > ResourceHandler:
> >
> > public MyResourceHandler(ResourceHandler wrapped) {
> > this.wrapped = wrapped;
> > }
>
> Eh, you're right.
>
> Now I see
> com.sun.faces.config.processor.AbstractConfigProcessor#createInstance works
> that way...
>
> Thank you very much.
>
> Shouldn't this be better stated in the JSF specs?
>
> Regards,
>
> Giampaolo
>
>
> > On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
> > > Hi,
> > >
> > > I have a (hopefully basic) question about implementing and
> > instantiating a
> > > ResourceHandlerWrapper in JSF 2.0.
> > >
> > > How can I wrap in a ResourceHandlerWrapper any "underlying"
> > ResourceHandler?
> > >
> > > I'm working on a library which would need to override some of the
> > behavior
> > > defined by the ResourceHandler, but I would like to be kind with the
> > > specific JSF 2.0 flavor my library may be going to run on.
> > >
> > > In example, I would like to avoid to make a direct reference to the
> > > com.sun.faces.application.resource.ResourceHandlerImpl in my
> > > ResourceHandlerWrapper implementation. Also, if a third-party library
> > is
> > > actually wrapping any "official" ResourceHandler implementation, I
> > would
> > > like to avoid breaking things by letting my library directly wrap the
> > > official handler, and instead wrap the third-party one.
> > >
> > > Is there any way to do this?
> > >
> > > I attempted looking for a reply to this at the JSF 2.0 specifications
> > as
> > > well as to the JSF-ri documents and sources, but I was unable to find
> > any.
> > >
> > > Thank you in advance,
> > >
> > > Giampaolo
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
> > >
> >
> >
> > --
> > Jason Lee
> > Senior Member of Technical Staff
> > GlassFish Administration Console
> >
> > Oracle Corporation
> > Phone +1 405-216-3193
> > Blog http://blogs.steeplesoft.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

Giampaolo Tomassoni

> Agreed that it could be more clear, but I was looking at the javadoc,
> not the spec.  I finally found the info in Ed Burns book page 361.
>
> One gotcha I found was that if you want to override createResource,
> then you also must override handleResourceRequest, because the wrapper
> implementation of handleResourceRequest delegates to the wrapped instance,
> which calls its own createResource instead of the one you implemented
> in your extension of ResourceHandlerWrapper.

Nah. At least, not in mojarra-2.0.3.

This is from
com.sun.faces.application.resource.ResourceHandlerImpl#handleResourceRequest
:

resource =
context.getApplication().getResourceHandler().createResource(resourceName,
libraryName);

However, I don't know if there is any gotcha of the kind you pointed out.

I have to code my own handleResourceRequest method anyway, so.

> Good luck,

Thank you, Joel.

Giampaolo

>
> Joel
> http://digitaljoel.nerd-herders.com
>
On Fri, Sep 24, 2010 at 10:36 AM, Giampaolo Tomassoni
wrote:
>   I think you can do that by adding a constructor that takes a
> ResourceHandler:
>
> public MyResourceHandler(ResourceHandler wrapped) {
>      this.wrapped = wrapped;
> }
Eh, you're right.

Now I see
com.sun.faces.config.processor.AbstractConfigProcessor#createInstance works
that way...

Thank you very much.

Shouldn't this be better stated in the JSF specs?

Regards,

Giampaolo

> On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
> > Hi,
> >
> > I have a (hopefully basic) question about implementing and
> instantiating a
> > ResourceHandlerWrapper in JSF 2.0.
> >
> > How can I wrap in a ResourceHandlerWrapper any "underlying"
> ResourceHandler?
> >
> > I'm working on a library which would need to override some of the
> behavior
> > defined by the ResourceHandler, but I would like to be kind with the
> > specific JSF 2.0 flavor my library may be going to run on.
> >
> > In example, I would like to avoid to make a direct reference to the
> > com.sun.faces.application.resource.ResourceHandlerImpl in my
> > ResourceHandlerWrapper implementation. Also, if a third-party library
> is
> > actually wrapping any "official" ResourceHandler implementation, I
> would
> > like to avoid breaking things by letting my library directly wrap the
> > official handler, and instead wrap the third-party one.
> >
> > Is there any way to do this?
> >
> > I attempted looking for a reply to this at the JSF 2.0 specifications
> as
> > well as to the JSF-ri documents and sources, but I was unable to find
> any.
> >
> > Thank you in advance,
> >
> > Giampaolo
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
> >
>
>
> --
> Jason Lee
> Senior Member of Technical Staff
> GlassFish Administration Console
>
> Oracle Corporation
> Phone +1 405-216-3193
> Blog http://blogs.steeplesoft.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Joel Weight

That's great they've fixed that in 2.0.3. This is from 2.0.2 source, which
I implemented against.

com.sun.faces.application.resource.ResourceHandlerImpl#handleResourceRequest
...
resource = createResource(resourceName, libraryName);

Joel

On Fri, Sep 24, 2010 at 12:55 PM, Giampaolo Tomassoni <
Giampaolo@tomassoni.biz> wrote:

> > Agreed that it could be more clear, but I was looking at the javadoc,
> > not the spec. I finally found the info in Ed Burns book page 361.
> >
> > One gotcha I found was that if you want to override createResource,
> > then you also must override handleResourceRequest, because the wrapper
> > implementation of handleResourceRequest delegates to the wrapped
> instance,
> > which calls its own createResource instead of the one you implemented
> > in your extension of ResourceHandlerWrapper.
>
> Nah. At least, not in mojarra-2.0.3.
>
> This is from
>
> com.sun.faces.application.resource.ResourceHandlerImpl#handleResourceRequest
> :
>
> resource =
> context.getApplication().getResourceHandler().createResource(resourceName,
> libraryName);
>
>
> However, I don't know if there is any gotcha of the kind you pointed out.
>
> I have to code my own handleResourceRequest method anyway, so.
>
>
> > Good luck,
>
> Thank you, Joel.
>
> Giampaolo
>
>
> >
> > Joel
> > http://digitaljoel.nerd-herders.com
> >
> On Fri, Sep 24, 2010 at 10:36 AM, Giampaolo Tomassoni
> wrote:
> > I think you can do that by adding a constructor that takes a
> > ResourceHandler:
> >
> > public MyResourceHandler(ResourceHandler wrapped) {
> > this.wrapped = wrapped;
> > }
> Eh, you're right.
>
> Now I see
> com.sun.faces.config.processor.AbstractConfigProcessor#createInstance works
> that way...
>
> Thank you very much.
>
> Shouldn't this be better stated in the JSF specs?
>
> Regards,
>
> Giampaolo
>
>
> > On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
> > > Hi,
> > >
> > > I have a (hopefully basic) question about implementing and
> > instantiating a
> > > ResourceHandlerWrapper in JSF 2.0.
> > >
> > > How can I wrap in a ResourceHandlerWrapper any "underlying"
> > ResourceHandler?
> > >
> > > I'm working on a library which would need to override some of the
> > behavior
> > > defined by the ResourceHandler, but I would like to be kind with the
> > > specific JSF 2.0 flavor my library may be going to run on.
> > >
> > > In example, I would like to avoid to make a direct reference to the
> > > com.sun.faces.application.resource.ResourceHandlerImpl in my
> > > ResourceHandlerWrapper implementation. Also, if a third-party library
> > is
> > > actually wrapping any "official" ResourceHandler implementation, I
> > would
> > > like to avoid breaking things by letting my library directly wrap the
> > > official handler, and instead wrap the third-party one.
> > >
> > > Is there any way to do this?
> > >
> > > I attempted looking for a reply to this at the JSF 2.0 specifications
> > as
> > > well as to the JSF-ri documents and sources, but I was unable to find
> > any.
> > >
> > > Thank you in advance,
> > >
> > > Giampaolo
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
> > >
> >
> >
> > --
> > Jason Lee
> > Senior Member of Technical Staff
> > GlassFish Administration Console
> >
> > Oracle Corporation
> > Phone +1 405-216-3193
> > Blog http://blogs.steeplesoft.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

Giampaolo Tomassoni

> That's great they've fixed that in 2.0.3.  This is from
> 2.0.2 source, which I implemented against.
>
>
com.sun.faces.application.resource.ResourceHandlerImpl#handleResourceRequest
> ...
>             resource = createResource(resourceName, libraryName);
>

Well, great. But there is yet another nifty thing to pay attention to, then.

Browsing at the ResourceHandlerImpl class, one may get the idea that
overriding the

createResource(
String resourceName,
String libraryName,
String contentType
)

method would suffice to handle one's own special resources. Instead, it
doesn't since handleResourceRequest invokes:

createResource(
String resourceName,
String libraryName
)

which the lazy coder didn't override. So long, this method in turn invokes
createResource(resourceName, libraryName, null), but from the very same
instance!

handleResourceRequest was probably better doing:

resource = context
.getApplication()
.getResourceHandler()
.createResource(resourceName, libraryName, null)
;

and the one- and two-parameters versions of the createResource method should
"upgrade" to the next version via:

FacesContext
.getCurrentInstance()
.getApplication()
.getResourceHandler()
.createResource(resourceName, libraryName[, null])

The latter seems an overkill to me AND it seems to me specs this time don't
give any special meaning to any of the createResource() method versions. So,
if you need to override createResource(), do it for all three versions!

Besides, it seems to me that method overloading often messes things with
proxy patterns. Why specs proposed three overloaded versions of the same
method in first place?

Giampaolo

> Joel

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Giampaolo Tomassoni

> Shouldn't this be better stated in the JSF specs?

Which, by the way, isn't actually stated that bad.

Section 11.4.6, "Delegating implementation support", clearly explains it.

I couldn't see it because it's Friday?

Thanks again Jason.

Giampaolo

> Regards,
>
> Giampaolo
>
>
> > On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
> > > Hi,
> > >
> > > I have a (hopefully basic) question about implementing and
> > instantiating a
> > > ResourceHandlerWrapper in JSF 2.0.
> > >
> > > How can I wrap in a ResourceHandlerWrapper any "underlying"
> > ResourceHandler?
> > >
> > > I'm working on a library which would need to override some of the
> > behavior
> > > defined by the ResourceHandler, but I would like to be kind with
> the
> > > specific JSF 2.0 flavor my library may be going to run on.
> > >
> > > In example, I would like to avoid to make a direct reference to the
> > > com.sun.faces.application.resource.ResourceHandlerImpl in my
> > > ResourceHandlerWrapper implementation. Also, if a third-party
> library
> > is
> > > actually wrapping any "official" ResourceHandler implementation, I
> > would
> > > like to avoid breaking things by letting my library directly wrap
> the
> > > official handler, and instead wrap the third-party one.
> > >
> > > Is there any way to do this?
> > >
> > > I attempted looking for a reply to this at the JSF 2.0
> specifications
> > as
> > > well as to the JSF-ri documents and sources, but I was unable to
> find
> > any.
> > >
> > > Thank you in advance,
> > >
> > > Giampaolo
> > >
> > >
> > > -------------------------------------------------------------------
> --
> > > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > > For additional commands, e-mail: webtier-
> help@glassfish.dev.java.net
> > >
> >
> >
> > --
> > Jason Lee
> > Senior Member of Technical Staff
> > GlassFish Administration Console
> >
> > Oracle Corporation
> > Phone +1 405-216-3193
> > Blog http://blogs.steeplesoft.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Jason Lee

I think you can do that by adding a constructor that takes a
ResourceHandler:

public MyResourceHandler(ResourceHandler wrapped) {
this.wrapped = wrapped;
}

On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
> Hi,
>
> I have a (hopefully basic) question about implementing and instantiating a
> ResourceHandlerWrapper in JSF 2.0.
>
> How can I wrap in a ResourceHandlerWrapper any "underlying" ResourceHandler?
>
> I'm working on a library which would need to override some of the behavior
> defined by the ResourceHandler, but I would like to be kind with the
> specific JSF 2.0 flavor my library may be going to run on.
>
> In example, I would like to avoid to make a direct reference to the
> com.sun.faces.application.resource.ResourceHandlerImpl in my
> ResourceHandlerWrapper implementation. Also, if a third-party library is
> actually wrapping any "official" ResourceHandler implementation, I would
> like to avoid breaking things by letting my library directly wrap the
> official handler, and instead wrap the third-party one.
>
> Is there any way to do this?
>
> I attempted looking for a reply to this at the JSF 2.0 specifications as
> well as to the JSF-ri documents and sources, but I was unable to find any.
>
> Thank you in advance,
>
> Giampaolo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

--
Jason Lee
Senior Member of Technical Staff
GlassFish Administration Console

Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Giampaolo Tomassoni

> I think you can do that by adding a constructor that takes a
> ResourceHandler:
>
> public MyResourceHandler(ResourceHandler wrapped) {
> this.wrapped = wrapped;
> }

Eh, you're right.

Now I see
com.sun.faces.config.processor.AbstractConfigProcessor#createInstance works
that way...

Thank you very much.

Shouldn't this be better stated in the JSF specs?

Regards,

Giampaolo

> On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
> > Hi,
> >
> > I have a (hopefully basic) question about implementing and
> instantiating a
> > ResourceHandlerWrapper in JSF 2.0.
> >
> > How can I wrap in a ResourceHandlerWrapper any "underlying"
> ResourceHandler?
> >
> > I'm working on a library which would need to override some of the
> behavior
> > defined by the ResourceHandler, but I would like to be kind with the
> > specific JSF 2.0 flavor my library may be going to run on.
> >
> > In example, I would like to avoid to make a direct reference to the
> > com.sun.faces.application.resource.ResourceHandlerImpl in my
> > ResourceHandlerWrapper implementation. Also, if a third-party library
> is
> > actually wrapping any "official" ResourceHandler implementation, I
> would
> > like to avoid breaking things by letting my library directly wrap the
> > official handler, and instead wrap the third-party one.
> >
> > Is there any way to do this?
> >
> > I attempted looking for a reply to this at the JSF 2.0 specifications
> as
> > well as to the JSF-ri documents and sources, but I was unable to find
> any.
> >
> > Thank you in advance,
> >
> > Giampaolo
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> > For additional commands, e-mail: webtier-help@glassfish.dev.java.net
> >
>
>
> --
> Jason Lee
> Senior Member of Technical Staff
> GlassFish Administration Console
>
> Oracle Corporation
> Phone +1 405-216-3193
> Blog http://blogs.steeplesoft.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

Jason Lee

Definitely. If I recall correctly, I had to ask Ryan Lubke how to do
that. ;)

On 9/24/10 11:36 AM, Giampaolo Tomassoni wrote:
>> I think you can do that by adding a constructor that takes a
>> ResourceHandler:
>>
>> public MyResourceHandler(ResourceHandler wrapped) {
>> this.wrapped = wrapped;
>> }
> Eh, you're right.
>
> Now I see
> com.sun.faces.config.processor.AbstractConfigProcessor#createInstance works
> that way...
>
> Thank you very much.
>
> Shouldn't this be better stated in the JSF specs?
>
> Regards,
>
> Giampaolo
>
>
>> On 9/24/10 10:53 AM, Giampaolo Tomassoni wrote:
>>> Hi,
>>>
>>> I have a (hopefully basic) question about implementing and
>> instantiating a
>>> ResourceHandlerWrapper in JSF 2.0.
>>>
>>> How can I wrap in a ResourceHandlerWrapper any "underlying"
>> ResourceHandler?
>>> I'm working on a library which would need to override some of the
>> behavior
>>> defined by the ResourceHandler, but I would like to be kind with the
>>> specific JSF 2.0 flavor my library may be going to run on.
>>>
>>> In example, I would like to avoid to make a direct reference to the
>>> com.sun.faces.application.resource.ResourceHandlerImpl in my
>>> ResourceHandlerWrapper implementation. Also, if a third-party library
>> is
>>> actually wrapping any "official" ResourceHandler implementation, I
>> would
>>> like to avoid breaking things by letting my library directly wrap the
>>> official handler, and instead wrap the third-party one.
>>>
>>> Is there any way to do this?
>>>
>>> I attempted looking for a reply to this at the JSF 2.0 specifications
>> as
>>> well as to the JSF-ri documents and sources, but I was unable to find
>> any.
>>> Thank you in advance,
>>>
>>> Giampaolo
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
>>> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>>>
>>
>> --
>> Jason Lee
>> Senior Member of Technical Staff
>> GlassFish Administration Console
>>
>> Oracle Corporation
>> Phone +1 405-216-3193
>> Blog http://blogs.steeplesoft.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

--
Jason Lee
Senior Member of Technical Staff
GlassFish Administration Console

Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net