JSF – Duplicate componentID

Java EE, Programação 4 Comments

Utilizando o DataTable do RichFaces em uma simples página, após um reload na página sempre era retornado o seguinte erro:

Duplicate component ID '_id0:_dataTable:_id1' found in view.

Segue abaixo o código da página que causava o erro:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich">

	<h:form binding="#{UserConsultPage.component}">
		<rich:dataTable id="dataTable"
			binding="#{UserConsultPage.dataTable}" var="item">
			<rich:column>
				<f:facet name="header">
					<h:outputText value="Name" />
				</f:facet>
				<h:outputText value="#{item.name}" />
			</rich:column>
			<rich:column>
				<f:facet name="header">
					<h:outputText value="Email" />
				</f:facet>
				<h:outputText value="#{item.email}" />
			</rich:column>
		</rich:dataTable>

		<h:commandButton id="btnLoad" actionListener="#{UserConsultPage.load}" />
	</h:form>

</ui:composition>

A solução foi colocar id’s em todos os componentes “outputText”. Segue abaixo a página modificada:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich">

	<h:form binding="#{UserConsultPage.component}">
		<rich:dataTable id="dataTable"
			binding="#{UserConsultPage.dataTable}" var="item">
			<rich:column>
				<f:facet name="header">
					<h:outputText id="headerNameValue" value="Name" />
				</f:facet>
				<h:outputText id="nameValue" value="#{item.name}" />
			</rich:column>
			<rich:column>
				<f:facet name="header">
					<h:outputText id="headerEmailValue" value="Email" />
				</f:facet>
				<h:outputText id="emailValue" value="#{item.email}" />
			</rich:column>
		</rich:dataTable>

		<h:commandButton id="btnLoad" actionListener="#{UserConsultPage.load}" />
	</h:form>

</ui:composition>