如果组件是ajax更新,则不执行commandButton

时间:2013-07-30 09:56:41

标签: ajax jsf primefaces

当我设置ajax =“false”时,以下简化的代码正在工作。使用ajax =“true”时,第二个commandButton在按下Button1或Button2后被推送时不会调用personPM.commitEditPerson()。

有人可以帮我解决这里的错吗?因为它似乎不容易解决,我添加了可以轻松复制的整个代码(JSF 2.2,Primefaces是3.5,GlassFish 4.0):

<?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://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
            <h:form id="f1">                    
                <p:commandButton id="Button1" update=":neuePerson" value="Neue Person" action="#{testPM.setCurrentPerson()}"/>
            </h:form>

            <h:panelGroup id="neuePerson">
                <h:form id="f2" >
                    <p:commandButton id="Button2" update=":neuePerson" value="Übernehmen" action="#{testPM.commitEditPerson()}"/>
                </h:form>
            </h:panelGroup>
    </h:body>
</html>

Session Scoped Bean TestPM.java:

package at.feimas.administration.presentation;

import java.util.logging.Level;
import java.util.logging.Logger;

public class TestPM {

    private String currentPerson;
    private String firstName;

    private static final Logger logger = Logger.getLogger(TestPM.class.getName());

    public void setCurrentPerson() {
        logger.log(Level.INFO, "New Person");
    }    
    public void commitEditPerson(){
        logger.log(Level.INFO, "Edit Person");
    }    
}

1 个答案:

答案 0 :(得分:0)

问题是由版本不匹配导致PF 3.5还没有为JSF 2.2做好准备!我使用PF快照4.0并且它有效。

此代码应显示整个问题以及如何使用PF 3.5和JSD 2.2解决它,但我强烈建议使用可以协同工作的版本!:

<h:body>
    <h:form id="f1">                    
        <p:commandButton id="Button1" update=":f2:buttonpanel2" value="New Person" actionListener="#{testPM.setFirstName}"/>
    </h:form>

    <h:panelGroup id="buttonpanel1">
        <h:form id="f2">      
            <h:panelGroup id="buttonpanel2">
                <h:outputText value="#{testPM.firstName}" id="firstName"/>                
                <p:commandButton id="Button2" update=":f2:buttonpanel2" value="Apply" actionListener="#{testPM.commitEditPerson}"/>
            </h:panelGroup>
        </h:form>          
    </h:panelGroup>
</h:body>

如果按钮使用&#39; update =&#34;:buttonpanel1&#34;&#39;这导致了我在问题中发布的行为:一旦更新发生,表单f2就不再起作用了。如果按钮使用&#39;更新=&#34;:f2:buttonpanel2&#34;&#39;一切都按预期工作。

相关问题