使用具有绑定和会话范围的数据表时,已在视图中找到组件ID [英] Component ID has already been found in the view when using datatable with binding and Session Scoped

查看:163
本文介绍了使用具有绑定和会话范围的数据表时,已在视图中找到组件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XHTML页面,提交后可以返回到它本身. 支持bean是会话作用域的.在重定向到自身时,页面将h:datatable渲染两次,并给我重复的id错误.我可以直观地看到该表彼此相邻渲染了两次.

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页面:**

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

这是显示的错误消息:

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

推荐答案

binding属性应绑定到请求范围的Bean或将其完全删除,并根据具体的功能要求用更好的替代方法替换.

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.

如果我获得了能够在editEcoleItem()方法中检索当前项目的功能要求,那么就可以直接将其作为方法参数传递,就像在deleteEcole()中所做的一样.这样,您就可以完全删除binding属性.这就是JSF 2.0/EL 2.2的方式.也许您过于关注旧的JSF 1.x示例.使用JSF 2.x进行开发时,您不应该这样做.

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.

  • A JSF 2.0 CRUD example
  • How can I pass selected row to commandLink inside dataTable?

这篇关于使用具有绑定和会话范围的数据表时,已在视图中找到组件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆