Hi Simon,
simon wrote:
Hi Ole,
It is good to know that Facelets adds attributes automatically.
Yes it's great. Kudos to Jacob!
Yes, I guess it would be possible to modify
HtmlRendererUtils.renderHtmlAttributes
to also look into the component it is passed for extra attributes that
it should write. It does mean retrieving the FacesContext from the
current thread and using that to get the configuration data (the names
of "magic" attributes) but that doesn't seem too evil to me.
But a ResponseWriter-based approach can do very much the same thing.
Would that work sort of like this (99% your and Andrew's material I think):
//responseWriter.startFormElement...
//write the normal form attributes
//call responseWriter.writeAdditionalAttributes()
//close starting Element
And I think you indicated that the response writer would know how to write the the additional
attribute because it would have a namespace prefix like "additionalAttribute:". I guess
this prefix could be made configurable? Also what if the whole attribute name was configurable.
So if the attribute entry was keyed with name "ajaxComponent"...then send it through.
The advantage of doing it in HtmlRenderUtils is that it should work
better for components that output multiple HTML tags. In this case, the
renderer would normally invoke this method only for the "main" element.
If I understand correctly, it now seems that the HtmlRendererUtils is fine doing what
it's doing currently, and that the renderers should just do a
responseWriter.writeAdditionalAttributes() inside encodeBegin, which would take care of
this "Developer Use Case" entirely.
However the advantage of doing it in ResponseWriter is that it will work
for all JSF components, not just the MyFaces ones. I think that is
extremely useful..
Indeed. I'd like to give this a shot and would be delighted if it became part
of the core or if it became useful in general...assuming I get it?
I think the task plan would be something like this:
- Understand how to configure a new ResponseWriter for JSF (We need to plugin a
new one right?)
- Subclass the existing response writer
- Add the renderAdditionalAttributes() method.
- Figure out where the ResponseWriter gets it's configuration from...web.xml?
- Pass the necessary configuration so that renderAdditionalAttributes() has
access.
And the rest is pretty easy I think...
Thanks again for the "Brain Jumping",
- Ole