使用< c:if>时出现重复ID异常带有复合组件 [英] Duplicate ID exception when using <c:if> with composite component

查看:70
本文介绍了使用< c:if>时出现重复ID异常带有复合组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有条件地将复合组件与<c:if>一起使用时,我得到重复的ID异常 我知道这个编译/渲染时间问题,但是我真的不知道为什么下面的示例不起作用. 请看以下三个简单的片段

I get a duplicate ID exception when using composite components conditionally with <c:if> I'm aware of this compile/render time issue but i have really no clue why the example below does not work. Please have a look at the following three simple snippets

一个名为 TestBean 的会话作用域bean,其中包含一个布尔值和两个将这个值更改为true或false的ajax侦听器:

A session scoped bean named TestBean which holds a boolean value and two ajax listeners which change this value to true or false:

@Named
@SessionScoped
public class TestBean implements Serializable {

    private boolean isVisible = false;

    public void onSetItemVisible(AjaxBehaviorEvent e) {
        this.isVisible = true;
    }

    public void onSetItemInvisible(AjaxBehaviorEvent e) {
        this.isVisible = false;
    }

    public boolean isItemVisible()  {
        return this.isVisible;
    }
}

一个非常简单的名为 testCmp 的复合组件:

A really simple composite component named testCmp:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:cc="http://java.sun.com/jsf/composite">

    <cc:interface/>
    <cc:implementation>
        <h:outputText id="text" value="text"/>
     </cc:implementation>
</html>

还有一个视图页面,允许在隐藏/显示此复合组件之间进行切换

And a view page which allows switching between hide/show this composite component

<h:body>
    <h:form id="testForm">

        <c:if test="#{testBean.itemVisible}">
            <test:testCmp id="test1"/>
        </c:if>
        <p/>

        <test:testCmp id="test2"/>
        <p/>

        <!-- show/hide dynamic item -->
        <h:commandLink value="Show Item">
            <f:ajax execute="@this" listener="#{testBean.onSetItemVisible}" render="@form"/> 
        </h:commandLink>
        <br/>
        <h:commandLink value="Hide Item">
            <f:ajax execute="@this" listener="#{testBean.onSetItemInvisible}" render="@form"/>
        </h:commandLink>
    </h:form>
</h:body>

问题是:在显示/隐藏之间切换时,我得到重复的ID异常. 异常显示:在视图中已经找到组件ID testForm:test2:text"

The thing is: i get a duplicate ID Exception when i switch between show/hide. Exception says: "Component ID testForm:test2:text has already been found in the view"

它抱怨'test2'...没有有条件添加的组件. 当我不使用复合组件并将其替换为<h:outputText>之类的标准组件时,则一切正常. 要重现此错误,重要的是,复合组件在同一页面上使用两次,一次使用该条件,而另一次不使用该条件.

It complains about 'test2' ... the component which is not conditionally added. And when i don't use a composite component and replace it with a standard component like <h:outputText> then anything works well. To reproduce the error it is important, that the composite component is used two times at the same page, one times with and the other times without the condition.

进一步搜索后,我发现了另一个我也遇到同样问题的人.但是他的例子看起来更复杂,更难复制. 在JSF中重复使用组件ID中的组件ID两次查看

After further searching i found another guy which i think has the same problem like me. But his example looks a bit more complex and is harder to reproduce. Duplicate component ID in JSF using composite component twice in view

有人知道这是怎么回事吗? 我的设置是带有Mojarra JSF 2.2.14的JBoss EAP7(但我也使用JSF 2.3.0-m11进行了测试) 有人可以确认这个问题吗? 如果是这样,我会为mojarray的家伙创建一个bug.

Anybody has a clue whats going on here? My setup is JBoss EAP7 with Mojarra JSF 2.2.14 (but i tested with JSF 2.3.0-m11 too) Can someone can confirm this problem? If so i'll create a bug for the mojarray guys.

推荐答案

这绝对是Mojarra中的错误,并且与在某些情况下处理动态组件树的修改有关.

This is definitely a bug in Mojarra and is related to handling of dynamic component tree modifications in certain situations.

我创建了一个复制器,提出了一个问题,并将有关我的发现的内容写到了mojarra dev邮件列表中.请在> https://github.com/tuner/mojarra-dynamic-include-复制者

I have created a reproducer, filed an issue and written about my findings to mojarra dev mailing list. Please read more at https://github.com/tuner/mojarra-dynamic-include-reproducer

这篇关于使用&lt; c:if&gt;时出现重复ID异常带有复合组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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