>From: "Manfred K." <[EMAIL PROTECTED]> 
>
> 
> Hi Martin, 
> 
> thanks for your reply. I get the correct instance of my custom UIViewRoot, 
> but the encodeBegin and encodeEnd methods never get called. I need a place, 
> where I can access the ResponseWriter to replace it with a StringWriter 
> (newResponseWriter = responseWriter.cloneWithWriter(stringWriter)). In a 
> PhaseListener and custom ViewHandler facesContext.getResponseWriter returns 
> null. 
> Perhaps there is another way to get the rendered html content before it gets 
> forwarded to the client... 
> 
> Do you have any ideas how I can achieve this? 
> 

You can create a custom view handler to look for a url pattern and override the 
behavior only for specific viewId's [1].  The view handler is passed the 
original on the constructor.  You simple delegate to the original when you 
don't need to override behavior.  You need to register your custom view handler 
in the faces-config.xml [2].

Trididad has a slick extension to the view handler that it calls an internal 
view.  The framework uses it for launching dialogs and other custom views.  
Depending on what your are doing, it is a simplified API.  Internal views are 
activated by special viewId's.  You register these special view Id's in a 
properties file that is located in the META-INF folder of the web project or a 
jar [3].  

The properties file has to be named 
"org.apache.myfaces.trinidad.render.InternalView.properties".  The key in the 
properties file is the viewId and the value is the fully qualified classpath to 
the handler [4].  The viewId doesn't need the URI suffix, 
"/viewId=com.acme.myhandler".

Another method for robbing the response writer of it's content is to plugin 
your own renderer [5].  Shale Validador does this kind of thing to inject some 
java script into the rendered markup.  The goal was to add script without 
having to create renderers for every component library that might use the shale 
commons validator.  On the surface, this seems like a good idea but doesn't 
always work with other component libraries that play the same tricks.  


ViewHandler
[1] 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/faces/ClayViewHandler.java?view=markup
[2] 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/resources/META-INF/faces-config.xml?view=markup

Trinidad Internal View
[3] 
http://svn.apache.org/viewvc/shale/sandbox/shale-clay-trinidad/src/main/resources/META-INF/org.apache.myfaces.trinidad.render.InternalView.properties?view=markup
[4] 
http://svn.apache.org/viewvc/shale/sandbox/shale-clay-trinidad/src/main/java/org/apache/shale/clay/PageHandler.java?view=markup

Renderer
[5] 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-validator/src/main/java/org/apache/shale/validator/faces/ValidatorCommandRenderer.java?view=markup


Gary

> TIA 
> 
> 
> Martin Marinschek wrote: 
> > 
> > I would think your original idea should work. What kind of UIViewRoot 
> > component do you get in the ViewHandler, can you start a debugging 
> > session? 
> > 
> > regards, 
> > 
> > Martin 
> > 
> > On 9/16/07, Andrew Robinson wrote: 
> >> FYI, if that doesn't work, you can customize the ViewHandler and set 
> >> it there using the method: 
> >> 
> >> public abstract void renderView(javax.faces.context.FacesContext 
> >> context, javax.faces.component.UIViewRoot viewToRender) 
> >> 
> >> 
> >> 
> >> On 9/16/07, Andrew Robinson wrote: 
> >> > I haven't actually tried it, but I think the easiest way would be to 
> >> > have a PhaseListener set it in the before render phase. There are 
> >> > wrappers on the ResponseWriter you can use to decorate the existing 
> >> > one (see ResponseWriterWrapper in shared_tomahawk). 
> >> > 
> >> > It is as simple as 
> >> FacesContext.getCurrentInstance().setResponseWriter(obj); 
> >> > 
> >> > On 9/16/07, Manfred K. wrote: 
> >> > > 
> >> > > Andrew, thanks for your hint! 
> >> > > 
> >> > > How can I register a custom responsewriter (in faces-config.xml)? I 
> >> cannot 
> >> > > create a custom component, place it around all other jsf tags in the 
> >> pages 
> >> > > and use the new responsewriter in the encodebegin method. 
> >> Unfortunately it's 
> >> > > not possible to modify the existing pages for this requirement. 
> >> > > 
> >> > > 
> >> > > 
> >> > > Andrew Robinson-5 wrote: 
> >> > > > 
> >> > > > You could replace the responsewriter and have full control over the 
> >> output 
> >> > > > 
> >> > > > On 9/15/07, Manfred K. wrote: 
> >> > > >> 
> >> > > >> Thank you for your reply! 
> >> > > >> 
> >> > > >> We are using myfaces (1.1.5). 
> >> > > >> I just had a look at the standard ViewHandler implementation, but 
> >> I don't 
> >> > > >> think that this is the right place for our needs. We have to 
> >> modify the 
> >> > > >> generated html output of the UIViewRoot (e.g. remove html, head, 
> >> body 
> >> > > >> tags 
> >> > > >> if present, add javascript code and log the modified html code). 
> >> How can 
> >> > > >> we 
> >> > > >> achieve this (what is the right place for this functionallity and 
> >> how can 
> >> > > >> we 
> >> > > >> access the generated html markup)? 
> >> > > >> 
> >> > > >> Thanks! 
> >> > > >> 
> >> > > >> 
> >> > > >> 
> >> > > >> Volker Weber-5 wrote: 
> >> > > >> > 
> >> > > >> > Hi, 
> >> > > >> > 
> >> > > >> > Did you use RI or myfaces? RI 1.1 did not support replacing the 
> >> > > >> > UIViewRoot component. Than you need to replace the ViewHandler 
> >> like we 
> >> > > >> > did in tobago. 
> >> > > >> > 
> >> > > >> > 
> >> > > >> > Regards, 
> >> > > >> > Volker 
> >> > > >> > 
> >> > > >> > 
> >> > > >> > 
> >> > > >> > 
> >> > > >> > 2007/9/15, Manfred K. : 
> >> > > >> >> 
> >> > > >> >> Hi all, 
> >> > > >> >> 
> >> > > >> >> I implemented a custom UIViewRoot because I need to override 
> >> the 
> >> > > >> >> encodeBegin 
> >> > > >> >> and encodeEnd methods. Unfortunately my methods never get 
> >> called!? 
> >> > > >> >> 
> >> > > >> >> I declared my UIViewRoot class in faces-config as new 
> >> component: 
> >> > > >> >> 
> >> > > >> >> 
> >> > > >> >> javax.faces.ViewRoot 
> >> > > >> >> test.TestUIViewRoot 
> >> > > >> >> 
> >> > > >> >> 
> >> > > >> >> The class: 
> >> > > >> >> 
> >> > > >> >> public class TestUIViewRoot extends UIViewRoot { 
> >> > > >> >> public TestUIViewRoot() { 
> >> > > >> >> super(); 
> >> > > >> >> } 
> >> > > >> >> 
> >> > > >> >> public void encodeBegin(FacesContext context) throws 
> >> > > >> IOException 
> >> > > >> >> { 
> >> > > >> >> //do some stuff 
> >> > > >> >> super.encodeBegin(context); 
> >> > > >> >> } 
> >> > > >> >> 
> >> > > >> >> public void encodeEnd(FacesContext context) throws 
> >> IOException 
> >> > > >> { 
> >> > > >> >> //do some stuff 
> >> > > >> >> super.encodeEnd(context); 
> >> > > >> >> } 
> >> > > >> >> ... 
> >> > > >> >> } 
> >> > > >> >> 
> >> > > >> >> What I'm doing wrong? 
> >> > > >> >> 
> >> > > >> >> THANX! 
> >> > > >> >> -- 
> >> > > >> >> View this message in context: 
> >> > > >> >> 
> >> http://www.nabble.com/Custom-UIViewRoot-tf4447158.html#a12688634 
> >> > > >> >> Sent from the MyFaces - Users mailing list archive at 
> >> Nabble.com. 
> >> > > >> >> 
> >> > > >> >> 
> >> > > >> > 
> >> > > >> > 
> >> > > >> 
> >> > > >> -- 
> >> > > >> View this message in context: 
> >> > > >> http://www.nabble.com/Custom-UIViewRoot-tf4447158.html#a12694553 
> >> > > >> Sent from the MyFaces - Users mailing list archive at Nabble.com. 
> >> > > >> 
> >> > > >> 
> >> > > > 
> >> > > > 
> >> > > 
> >> > > -- 
> >> > > View this message in context: 
> >> http://www.nabble.com/Custom-UIViewRoot-tf4447158.html#a12698560 
> >> > > Sent from the MyFaces - Users mailing list archive at Nabble.com. 
> >> > > 
> >> > > 
> >> > 
> >> 
> > 
> > 
> > -- 
> > 
> > http://www.irian.at 
> > 
> > Your JSF powerhouse - 
> > JSF Consulting, Development and 
> > Courses in English and German 
> > 
> > Professional Support for Apache MyFaces 
> > 
> > 
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Custom-UIViewRoot-tf4447158.html#a12731400 
> Sent from the MyFaces - Users mailing list archive at Nabble.com. 
> 

Reply via email to