I have a XHTML page which on submission goes back to itself. The backing bean is session scoped. On the redirect to itself the page renders the h:datatable twice and gives me duplicate id error.I can visually see the table being rendered twice as well next to each other.
** xhtml page :**
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<h:form >
<h:dataTable binding="#{ecole.dataTable}" value="#{ecole.getEcoleList()}" var="c"
border="0" width="100%" cellpadding="0" cellspacing="0"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
<h:column>
<f:facet name="header">
ID
</f:facet>
#{c.idEcole}
</h:column>
<h:column>
<f:facet name="header">
Nom
</f:facet>
#{c.nomEcole}
</h:column>
<h:column>
<f:facet name="header">
Description
</f:facet>
#{c.desc_ecl}
</h:column>
<h:column>
<f:facet styleclass="options-width" name="header">
Options
</f:facet>
<h:commandLink action="#{ecole.editEcoleItem()}" title="Edit" >
<h:graphicImage style="border:0" url="/icones/b_edit.png" />
</h:commandLink>
   
<h:commandLink title="Delete"
onclick="return confirm('Voulez-vous confirmer la suppression?') ;"
action="#{ecole.deleteEcole(c)}"
>
<h:graphicImage style="border:0" url="/icones/b_drop.png" />
</h:commandLink>
</h:column>
</h:dataTable>
<!-- end product-table................................... -->
</h:form>
</f:view>
this is error message shown :
java.lang.IllegalStateException: Component ID j_id15:j_id16:j_id29 has already been found in the view. See below for details.
+id: null
type: javax.faces.component.UIViewRoot@1abe6f6
+id: javax_faces_location_HEAD
type: javax.faces.component.UIPanel@c84a5d
+id: j_id4
type: javax.faces.component.UIOutput@18a5776
+id: j_id22
type: javax.faces.component.UIOutput@1742dcc
+id: j_id19
...
The binding
attribute should bind to a request scoped bean or just be removed altogether and be replaced by a better alternative, depending on the concrete functional requirement.
If I get the functional requirement right of being able to retrieve the current item in the editEcoleItem()
method, then you can just pass it directly as method argument, exactly as you did in deleteEcole()
. This way you can just remove the binding
attribute altogether. That's the JSF 2.0 / EL 2.2 way. Perhaps you were focusing too much on old JSF 1.x examples. You shouldn't do that when developing with JSF 2.x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With