<h:body> really doesn't support it (admittedly, to my surprise, it works great for HTML). I reported this to the JSF guys as issue 2409 .
At the same time, assuming you are using Mojarra, you can solve this by extending the Mojarra BodyRenderer as follows:
package com.example; import java.io.IOException; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import com.sun.faces.renderkit.html_basic.BodyRenderer; public class BodyWithIdRenderer extends BodyRenderer { @Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { super.encodeBegin(context, component); if (component.getId() != null) { context.getResponseWriter().writeAttribute("id", component.getClientId(context), "id"); } } }
To run it, register it in faces-config.xml (no, the @FacesRenderer annotation magic will not work to override the standard renderers).
<render-kit> <renderer> <component-family>javax.faces.Output</component-family> <renderer-type>javax.faces.Body</renderer-type> <renderer-class>com.example.BodyWithIdRenderer</renderer-class> </renderer> </render-kit>
source share