7

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>
                             &#xa0;&#xa0;&#xa0;
                             <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
       ...
Ziko
  • 135
  • 1
  • 4
  • 10

1 Answers1

11

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.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • i remove the binding , and i changed **editEcoleItem()** as you mentioned in your answer and it works now . yeah you're right i was focusing too much on old JSF 1.x examples... not only you saved my day Mr.BalusC ,but you saved my project . now my project works perfectly ,and i don't know how to thank you !! during two month your tutorials were so helpful and your answers solved my problems . a big thank to you :) – Ziko Sep 10 '12 at 18:45
  • http://drewdev.blogspot.com/2009/01/jsf-component-binding-stinks.html As @BalusC said: we should not use binding with anything other than request scope. I just had this problem and after reading this answer, my doubt went away and my program is also now working. However, I do want to share a link that I found about why its not a good idea for this behaviour. Please go to the above URL if anyone needs to know the reason behind this answer. – Rash Sep 23 '14 at 18:12
  • @Rash: that blog stinks. Better refer http://stackoverflow.com/questions/12506679/what-is-component-binding-in-jsf-when-it-is-preferred-to-be-used – BalusC Sep 23 '14 at 18:38
  • @BalusC Nice, its even more clearer and short ;) Thanks!! – Rash Sep 23 '14 at 20:44