Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 使用具有绑定和会话作用域的datatable时,已在视图中找到组件ID_Jsf 2 - Fatal编程技术网

Jsf 2 使用具有绑定和会话作用域的datatable时,已在视图中找到组件ID

Jsf 2 使用具有绑定和会话作用域的datatable时,已在视图中找到组件ID,jsf-2,Jsf 2,我有一个XHTML页面,在提交时会自动返回。 支持bean是会话作用域。在重定向到自身的页面上,h:datatable呈现了两次,并给出了重复的id错误。我可以直观地看到该表在彼此旁边呈现了两次 **xhtml页面:** <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml

我有一个XHTML页面,在提交时会自动返回。 支持bean是会话作用域。在重定向到自身的页面上,h:datatable呈现了两次,并给出了重复的id错误。我可以直观地看到该表在彼此旁边呈现了两次

**xhtml页面:**

<?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>

binding
属性应该绑定到一个请求范围的bean,或者干脆全部删除,然后根据具体的功能需求用更好的替代方法替换

如果我正确地获得了能够在
editecoletem()
方法中检索当前项的功能需求,那么您可以直接将其作为方法参数传递,就像在
deleteEcole()
中一样。这样,您就可以完全删除
绑定
属性。这就是JSF2.0/EL2.2的方式。也许您过于关注旧的JSF1.x示例。在使用JSF2.x开发时不应该这样做

另见:

我删除了绑定,并按照您在回答中提到的更改了EditeCleItem(),现在它可以工作了。是的,你是对的,我把太多精力放在老的JSF1.x示例上了。。。巴卢斯克先生,你不仅救了我一天,而且还救了我的项目。现在我的项目运行得很好,我不知道如何感谢你!!在两个月的时间里,你们的辅导非常有帮助,你们的答案解决了我的问题。非常感谢:)正如@BalusC所说:我们不应该将绑定用于请求范围之外的任何东西。我刚刚遇到了这个问题,在阅读了这个答案后,我的怀疑消失了,我的程序也在运行。然而,我想分享一个我发现的关于为什么这不是一个好主意的链接。如果有人想知道这个答案背后的原因,请访问上面的URL。@Rash:那个博客真臭。最好参考@BalusC Nice,它更清晰、更简短;)谢谢
 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
       ...