You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Brad Smith <bg...@bendcable.com> on 2007/03/27 02:07:54 UTC

Custom ViewHandlers

I was wondering how a custom ViewHandler is managed in MyFaces. A custom
view handler seems to be an elegant solution to a problem I am dealing
with, yet I will also be using Facelets. 

Facelets uses a decorator pattern in it's ViewHandler, that is the
constructor takes a base ViewHandler as the only argument.  

I am wondering how to easily chain ViewHandlers so that my custom
ViewHandler can decorate the FaceletViewHander (or other ViewHandler
such as the default ViewHandler for MyFaces).

I am also looking at MyFaces source, but am hoping for a quicker answer
here.

Thanks,

Brad



Re: Custom ViewHandlers

Posted by Jörn Zaefferer <jo...@googlemail.com>.
The JSF 1.1 spec mentions the delegation in "10.3.5 Delegating
Implementation Support" (10-52).

>From what I've seen, Facelets delegates to the JSPViewHandler when it can't
find the specified view. So if you can't rely on the order of registered
view handlers, you have to rely on the handle-or-delegate behaviour. Seems
to work with Facelets, but I don't know how others deal with it.

On 3/28/07, Brad Smith <bg...@bendcable.com> wrote:
>
> Jörn - I do not know. Any examples that I have seen (e.g. Facelets with
> Trinidad or Facelets with Ajax4JSF) show Facelets being registered in
> web.xml via a custom context configuration.  I am having a difficult
> time finding any specification for JSF configuration file
> (faces-config.xml by default) that describes the delegation process.
>
> Brad
>
>
> On Tue, 2007-03-27 at 17:12 +0200, Jörn Zaefferer wrote:
> > Isn't the delegation supposed to allow registering of more then one
> > view handler?
>
>
>
>
>

Re: Custom ViewHandlers

Posted by Brad Smith <bg...@bendcable.com>.
Jörn - I do not know. Any examples that I have seen (e.g. Facelets with
Trinidad or Facelets with Ajax4JSF) show Facelets being registered in
web.xml via a custom context configuration.  I am having a difficult
time finding any specification for JSF configuration file
(faces-config.xml by default) that describes the delegation process.

Brad


On Tue, 2007-03-27 at 17:12 +0200, Jörn Zaefferer wrote:
> Isn't the delegation supposed to allow registering of more then one
> view handler?





Re: Custom ViewHandlers

Posted by Jörn Zaefferer <jo...@googlemail.com>.
Isn't the delegation supposed to allow registering of more then one view
handler?

On 3/27/07, Brad Smith <bg...@bendcable.com> wrote:
>
> Thank you Simon. Do you by chance know what to do when also using
> something like Facelets which also has a custom ViewHandler? I mean as
> far as how the faces config file would be set up?
>
> Thanks,
>
> Brad Smith
>
> On Tue, 2007-03-27 at 13:00 +1200, Simon Kitching wrote:
> > First write a subclass of ViewHandler that takes another ViewHandler as
> > a parameter to the constructor. This constructor will be called passing
> > the "preceding" viewhandler instance so you can chain calls to it from
> > your custom class.
> >
> > Second, add the following to your faces config file:
> >    <application>
> >      <view-handler>example.MyViewHandler</view-handler>
> >    </application>
> >
>
>
>

Re: Custom ViewHandlers

Posted by Brad Smith <bg...@bendcable.com>.
Thank you Simon. Do you by chance know what to do when also using
something like Facelets which also has a custom ViewHandler? I mean as
far as how the faces config file would be set up?

Thanks,

Brad Smith

On Tue, 2007-03-27 at 13:00 +1200, Simon Kitching wrote:
> First write a subclass of ViewHandler that takes another ViewHandler as 
> a parameter to the constructor. This constructor will be called passing 
> the "preceding" viewhandler instance so you can chain calls to it from 
> your custom class.
> 
> Second, add the following to your faces config file:
>    <application>
>      <view-handler>example.MyViewHandler</view-handler>
>    </application>
> 



Re: Custom ViewHandlers

Posted by Simon Kitching <si...@rhe.co.nz>.
Brad Smith wrote:
> I was wondering how a custom ViewHandler is managed in MyFaces. A custom
> view handler seems to be an elegant solution to a problem I am dealing
> with, yet I will also be using Facelets. 
> 
> Facelets uses a decorator pattern in it's ViewHandler, that is the
> constructor takes a base ViewHandler as the only argument.  
> 
> I am wondering how to easily chain ViewHandlers so that my custom
> ViewHandler can decorate the FaceletViewHander (or other ViewHandler
> such as the default ViewHandler for MyFaces).

It's very simple. I did it just a week or so ago; it was an attempt at 
fixing something that turned out easier in another way so I've deleted 
that code however here's what I remember:

First write a subclass of ViewHandler that takes another ViewHandler as 
a parameter to the constructor. This constructor will be called passing 
the "preceding" viewhandler instance so you can chain calls to it from 
your custom class.

Second, add the following to your faces config file:
   <application>
     <view-handler>example.MyViewHandler</view-handler>
   </application>

All done.

Regards,

Simon