Hi Guys,

I've been doing a little more investigating.  The myfaces HtmlFormRenderer
has this method in it:

HtmlRendererUtils.renderHTMLAttributes(writer, htmlForm, 
HTML.FORM_PASSTHROUGH_ATTRIBUTES);

So I'm assuming this method will let any attribute that is contained in 
HTML.FORMPASSTHROUGH_ATTRIBUTES
pass through.  I'm also assuming any tag attribute that the View compiler cannot 
match to a component property is stored on the UIComponent.attributes list...which 
makes me wonder why <f:attribute> is needed...I'm hoping it's there just in 
case an implementation wanted to support a very strict Page compiler policy of only 
setting declared component properties.

So I'm going to try appending the attribute to the 
HTML.COMMON_PASSTHROUGH_ATTRIBUTES, which are included
in HTML.FORMPASSTHROUGH_ATTRIBUTES and see if that lets it get through.  All 
fingers crossed, as this would make life reel easy.

Cheers,
- Ole





simon wrote:
Hmm..interesting suggestion, Andrew.

So a custom responsewriter could potentially be written to allow the
insertion of new attributes onto the html tag for any component?

Is this what you were thinking of?

startElement(String ename, UIComponent component) {
   // start xml element
   // if (component not in already-processed list)
   //   for each key in component.getAttributes()
   //     if key.startsWith("tunnelledAttribute:")
   //       output (key, value) as xml attributes
   // store component in already-processed list
}

Then:
  <h:someTag ..>
    <f:attribute name="tunnelledAttribute:foo" value="bar"/>

That might be interesting to add to the standard MyFaces
ResponseWriter...

Regards,

Simon

On Fri, 2007-12-14 at 19:54 -0700, Andrew Robinson wrote:
Most renderers will not give you access to the root element to be able
to add attributes. However, if the renderers are correctly using the
response writer, they should be calling startElement(String,
UIComponent). By subclassing this, you can trap the call, look for you
attributes and add them to the element.

-Andrew

On Dec 14, 2007 7:07 PM, Ole Ersoy <[EMAIL PROTECTED]> wrote:
Hi,

I have a attribute that I just need to get passed through to the corresponding 
html element.  For example:

<h:form id="registrationForm"
        anAdditionalAttribute="I need to get through to the form element">
</h:form>


In the rendered output I would like:

<form
        ...
        anAdditionalAttribute="I need to get through to the form element">
</form>


I think the process for doing this (Excluding component registration, etc.) is first to 
subclass the form component and add the "anAdditionalAttribute" to the 
subclass.  Then subclass the corresponding renderer and render this attribute.

Does anyone know if there's a quicker/magic way to get the job done?

Thanks,
- Ole





Reply via email to