Add custom attributes with custom Renderer without extends Mysfaces Renderer
----------------------------------------------------------------------------
Key: MYFACES-3371
URL: https://issues.apache.org/jira/browse/MYFACES-3371
Project: MyFaces Core
Issue Type: Bug
Components: General
Affects Versions: 2.1.3
Environment: Windows 7, Glassfish 3.1, Oracle JVM 1.6
Reporter: Juan Fernandez Corugedo
I have created a custom render kit with some renderers. If the application
request a renderer that is not registered in the render kit, it delegates the
request to the HTML_BASIC renderkit:
public Renderer getRenderer(String family, String rendererType) {
Renderer renderer = null;
HashMap<String,Renderer> renderers =
rendererFamilies.get(family);// In this Map I have put all the registered
renderers
if(renderers != null){
renderer = renderers.get(rendererType);
}
if(renderer == null){
//There are not any renderer defined for this Family
and Rendertype, delegating the request to the HTML_BASIC renderkit
FacesContext context =
FacesContext.getCurrentInstance();
RenderKit renderKit =
getRenderKitFactory().getRenderKit(context, "HTML_BASIC");
return renderKit.getRenderer(family, rendererType);
}
return ((renderers != null) ? renderers.get(rendererType) : null);
}
In the other hand, each Renderer performs some operations (add custom
attributes, validations, etc...) and then delegate the process to the Renderer
of the HTML_BASIC renderkit:
CustomInputTextRenderer extends Renderer{
...
@Override
public void encodeEnd(FacesContext context, UIComponent component)
throws IOException {
//DO SOME CUSTOM OPERATIONS LIKE ADD CUSTOM ATTRIBUTES
// Then, call to the same method of the HTML_BASIC Renderer
RenderKitFactory renderKitFactory =
(RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
RenderKit renderKit = renderKitFactory.getRenderKit(context,
"HTML_BKS");
renderKit.getRenderer(component.getFamily(),
component.getRendererType()).encodeEnd(context, component);
}
}
With this approach, there are not need of any class to extend any of the
Myfaces renderer, so the application is decoupled from the JSF implementation.
This approach works good with Mojarra (2.1.0), because the Mojarra Renderers
calls the ResponseWriter.startElement() in the Renderer.encodeBegin() and it
calls the ResponseWriter.endElement() in the Renderer.encodeEnd().
But with Myfaces (2.1.3) it does not work, because the Myfaces Renderers calls
both ResponseWriter.startElement() and ResponseWriter.endElement() in the same
method (Renderer.encodeEnd()), so there are not any way to insert code between
these two calls without extends all the Myfaces Renderers.
This can be solved by changing all the Renderers (well, not all, the
FormRenderer is ok, it calls the startElement in the encodeBegin and the
endElement in the encodeEnd) moving the startElement call to the encodeBegin
method.
Greetings.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira