jsfradio-buttonjsf-2.2passthrough-elements

name attribute overriden when specifying input type="radio" as JSF passthrough element


When using plain HTML radio buttons bound to a bean using the jsf: attributes added in JSF 2.2, I run into an issue where the generated names of the radio inputs don't match:

<label>
     <input type="radio" value="foo" name="a-radio" jsf:id="fooOption" jsf:value="#{fooBean.value} />
</label>
<label>
     <input type="radio" value="bar" name="a-radio" jsf:id="barOption" jsf:value="#{fooBean.value} />
</label>

However, when the page is rendered, the name attributes of the inputs become "[some:jsf:id]:fooOption" and "[some:jsf:id]:barOption", meaning that checking one doesn't uncheck the other! Is this a bug, or does the jsf: attribute namespace not support radio buttons?


Solution

  • Specify the name as passthrough attribute instead. It will override the implicit attribute.

    <html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
    
    <label>
        <input type="radio" value="foo" a:name="a-radio" jsf:id="fooOption" />
    </label>
    <label>
        <input type="radio" value="bar" a:name="a-radio" jsf:id="barOption" />
    </label>
    

    You only need to redeclare it as <f:viewParam name="a-radio" value="#{fooBean.value}">, or to manually grab the submitted value from the request parameter map.