动态呈现的panelGroup内的CommandButton无法执行actionlistener

时间:2012-06-17 15:19:33

标签: java jsf

我有一个非常简单的xhtml文件,其中包含panelGroup的{​​{1}}在点击切换按钮时添加到页面中,但动态添加的commandButton无法执行其commandButton actionlistener被点击。

完整的代码如下:

<?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:p="http://primefaces.org/ui">

    <h:head>
    </h:head>
    <h:body>
        <h:panelGroup id="checkDyna">
            <h:panelGroup rendered="#{listRetriever.booleanStatus}" >
                <h:form>            
                    <p:commandButton value="check" process="@all" actionListener="#{listRetriever.xx()}"/>
                </h:form>
            </h:panelGroup>
        </h:panelGroup>
        <h:form>
            <p:commandButton value="Toggle" actionListener="#{listRetriever.toggleBooleanStatus()}" update=":checkDyna"/>
        </h:form>

    </h:body>
</html>

@ManagedBean(name = "listRetriever")
@RequestScoped
public class ListRetriever implements Serializable {

    private boolean booleanStatus;        

    public void toggleBooleanStatus(){
        if (!booleanStatus)
            booleanStatus=true;
    }

    public void xx(){
        System.out.println("Invoked***");
    }

    public boolean isBooleanStatus() {
        return booleanStatus;
    }

    public void setBooleanStatus(boolean booleanStatus) {
        this.booleanStatus = booleanStatus;
    }

}

成功调用删除rendered="#{listRetriever.booleanStatus}" actionlistener。

在制作bean ViewScoped时,问题也被消除了,但我不想让它比RequestScoped宽。

1 个答案:

答案 0 :(得分:0)

我在有条件渲染的面板中有p:commandButton,当我尝试执行actionlistener时,其渲染的条件表达式正在评估 false 。这是导致actionlistener无法执行的原因。