Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Ajax 在某些情况下,复合组件上的JSF客户端行为集会被触发两次_Ajax_Jsf_Jsf 2_Listener_Composite Component - Fatal编程技术网

Ajax 在某些情况下,复合组件上的JSF客户端行为集会被触发两次

Ajax 在某些情况下,复合组件上的JSF客户端行为集会被触发两次,ajax,jsf,jsf-2,listener,composite-component,Ajax,Jsf,Jsf 2,Listener,Composite Component,让我们以下面的例子为例: 复合构件如下所示: <?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" x

让我们以下面的例子为例:

复合构件如下所示:

<?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:cc="http://xmlns.jcp.org/jsf/composite"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <!-- INTERFACE -->
    <cc:interface>
        <cc:clientBehavior name="click" targets="button" event="click"/>
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <span id="#{cc.clientId}">
            <h:commandButton id="button" value="Press me">
                <f:ajax event="click" listener="#{bean.helloFromComposite()}"/>
            </h:commandButton>
        </span>
    </cc:implementation>
</html>
<h:form id="form">                   
    <my:button id="my-button">
        <f:ajax event="click" listener="#{bean.HelloFromPage()}"/>
    </my:button>
</h:form>
<h:form>                   
    <h:commandButton>
        <f:ajax event="click" listener="#{bean.helloOne()}"/>
        <f:ajax event="click" listener="#{bean.helloTwo()}"/>
    </h:commandButton>
</h:form>

使用页面如下:

<?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:cc="http://xmlns.jcp.org/jsf/composite"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <!-- INTERFACE -->
    <cc:interface>
        <cc:clientBehavior name="click" targets="button" event="click"/>
    </cc:interface>

    <!-- IMPLEMENTATION -->
    <cc:implementation>
        <span id="#{cc.clientId}">
            <h:commandButton id="button" value="Press me">
                <f:ajax event="click" listener="#{bean.helloFromComposite()}"/>
            </h:commandButton>
        </span>
    </cc:implementation>
</html>
<h:form id="form">                   
    <my:button id="my-button">
        <f:ajax event="click" listener="#{bean.HelloFromPage()}"/>
    </my:button>
</h:form>
<h:form>                   
    <h:commandButton>
        <f:ajax event="click" listener="#{bean.helloOne()}"/>
        <f:ajax event="click" listener="#{bean.helloTwo()}"/>
    </h:commandButton>
</h:form>

然后,当我单击按钮时,bean记录:

  • 你好,来自复合材料公司
  • 你好,来自第页
  • 你好,来自复合材料公司
  • 你好,来自第页
在Glassfish 4.1.1上复制,Omnifaces 2.5.1和Primefaces 6.0

如果我按以下方式更改使用页面,则问题消失:

<h:form id="form">                   
    <my:button id="my-button">
        <f:ajax event="click" listener="#{bean.HelloFromPage()}" execute="@none"/>
    </my:button>
</h:form>

当我单击按钮时,bean现在会记录:

  • 你好,来自复合材料公司
  • 你好,来自第页
我有两个问题:

  • 这是已知的行为吗
  • “组合中的Hello”、“页面中的Hello”序列是设计的吗?我觉得这没什么,因为在我看来,组合中的ajax行为比使用页面中指定的ajax行为更具体(应该首先执行)
  • 编辑: 我可以用一种非常简单的方法重现这个问题,如下所示:

    <?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:cc="http://xmlns.jcp.org/jsf/composite"
          xmlns:h="http://xmlns.jcp.org/jsf/html"
          xmlns:f="http://xmlns.jcp.org/jsf/core">
    
        <!-- INTERFACE -->
        <cc:interface>
            <cc:clientBehavior name="click" targets="button" event="click"/>
        </cc:interface>
    
        <!-- IMPLEMENTATION -->
        <cc:implementation>
            <span id="#{cc.clientId}">
                <h:commandButton id="button" value="Press me">
                    <f:ajax event="click" listener="#{bean.helloFromComposite()}"/>
                </h:commandButton>
            </span>
        </cc:implementation>
    </html>
    
    <h:form id="form">                   
        <my:button id="my-button">
            <f:ajax event="click" listener="#{bean.HelloFromPage()}"/>
        </my:button>
    </h:form>
    
    <h:form>                   
        <h:commandButton>
            <f:ajax event="click" listener="#{bean.helloOne()}"/>
            <f:ajax event="click" listener="#{bean.helloTwo()}"/>
        </h:commandButton>
    </h:form>
    
    
    
    通过在第二个AJAX调用中添加execute@none属性来解决:

    <h:form>                   
        <h:commandButton>
            <f:ajax event="click" listener="#{bean.helloOne()}"/>
            <f:ajax event="click" listener="#{bean.helloTwo()}" execute="@none"/>
        </h:commandButton>
    </h:form>
    
    
    
    按钮被“点击”和按钮被“执行”之间是否存在混淆