Nicklas Karlsson wrote:
Another approach would be to try and intercept stuff as each component
is rendered; for your purposes that's fine, yes? So how about this:
* Override the default RenderKit with a wrapper of your own.
* On each call to addRenderer(...), call:
super.addRenderer(new MyRendererWrapper(r));
so all the standard renderer objects have a custom wrapper around
them
* Your custom wrapper then intercepts encodeBegin(), and potentially
updates the component's "rendered" state before delegating on to the
real renderer.
So if I understand you correctly, I should create a
public class MyKit extends HtmlRenderKitImpl that overrides addRenderer
with something like
public void addRenderer(String componentFamily, String rendererType,
Renderer renderer) {
super(componentFamily, rendererType, new MyRenderer(renderer));
...
}
and then have a
public class MyRenderer extends Renderer {
private Render realRenderer;
public MyRenderer(Renderer realRenderer) {
this.realRenderer = realRenderer;
}
public void encodeBegin(FacesContext context, UIComponent component)
// Do magic with the component
realRenderer.encodeBegin(context, component);
}
}
Yep, that's what I was suggesting.
Do I have to use super.calls for all other mehtods in Renderer also?
Well, not "super", but "realRenderer.something".
Or
did you mean I have to make a wrapper for each component class?
Nope, that wouldn't be practical. And I don't believe it is necessary;
you want to do the same operation regardless of the actual component
type, yes? So I think a single wrapper will work for all.
And does
that mean I would have to define them all in faces-config? What is the
way that results in a) minimal number of custom classes, b) minimal
number of additonal configuration in faces-config? Preferrably both ;-)
No, because you've overridden the renderKit you shouldn't need to make
any other config changes; exactly the same standard renderers should be
created and registered as when using the standard RenderKit, except that
your custom one is wrapping them as they are created.
Actually, I believe my original email suggested overriding the
Application rather than the RenderKit. But you might be right that the
RenderKit is the correct thing to override to get this effect.
Please note that the approach I suggested is just *speculation*. I
haven't done this myself as I haven't needed to. It just looks to me
like an approach worth trying.
I also tried using Facelets for this as you suggested but was
unsuccessful. Tried both a phaselistener and by extending all the
mehtods in the facelet-viewhandler but was still unable to intercept :-/
Ah well.
Regards,
Simon