Binding attribute causes duplicate component ID found in the view
Duplicate component ID errors may occur when:
- Same ID is used on different components inside the same
NamingContainer
. - Physically different components are bound to the same property of the same bean.
- The
<f:subview>
is been declared in the include page instead of the parent page. - The same include page is included multiple times inside the same
NamingContainer
. - A component is been dynamically created without having an explicit ID assigned.
Here, NamingContainer
is among others the <h:form>
, <h:dataTable>
and <f:subview>
.
When using binding
, you should bind it to a property which is used exclusively by the component in question on a per-request basis. Your specific case indicates that this binding is been shared by multiple components, perhaps across different requests. When you bind the component to a property of a backing bean, then the backing bean should absolutely not be in a broader scope than the request scope. See also JSF 2.0 specitication chapter 3.1.5 (emphasis mine):
3.1.5 Component Bindings
...
Component bindings are often used in conjunction with JavaBeans that are dynamically instantiated via the Managed Bean Creation facility (see Section 5.8.1 “VariableResolver and the Default VariableResolver”). It is strongly recommend that application developers place managed beans that are pointed at by component binding expressions in “request” scope. This is because placing it in session or application scope would require thread-safety, since UIComponent instances depends on running inside of a single thread. There are also potentially negative impacts on memory management when placing a component binding in “session” scope.
See also:
- How does the 'binding' attribute work in JSF? When and how should it be used?
- How to use component binding in JSF right ? (request-scoped component in session scoped bean)
- View scope: java.io.NotSerializableException: javax.faces.component.html.HtmlInputText