为什么p:commandButton里面的p:dialog不会激活actionListener?

时间:2011-03-19 06:02:46

标签: jsf jsf-2 primefaces

<h:form prependId="false">

<p:dialog modal="true">

<p:commandLink ajax="true" value="ok" actionListener="Bean.listenerMethod"/>

</p:dialog>

</h:form>

我在表单中也有一些其他控件。单击链接时,未触发侦听器。可能是什么问题?请帮忙!

3 个答案:

答案 0 :(得分:2)

您需要将其声明为EL方法表达式,而不是普通字符串。

actionListener="#{Bean.listenerMethod}"

可以肯定的是,#{Bean}必须是一个有效的托管bean,其托管bean名称"Bean"又包含以下方法

public void listenerMethod(ActionEvent event) {
    // ...
}

其中ActionEvent来自javax.faces包,而不是java.awt包。

如果仍然无效,则由其他原因引起。例如。表单已嵌套,rendered属性已评估为false,等等。有关概述,请参阅this answer

答案 1 :(得分:1)

你应该使用<h:commandLink action="... /> 而不是<p:commandLink actionListener="... />

示例:

<h:commandLink id="elimina"
   action="#{listaBonificiModel.eliminaSelezionato()}"
   update="@(form)" oncomplete="PF('bonificoDialog').hide()"
   value ="Elimina" />

答案 2 :(得分:0)

尝试

<h:form id="mainform">
    __________
    __________
    <p:dialog id="test" widgetVar="Testing">
       <h:form>
          <h:panelGrid columns="1">
             _________
             _________
          </h:panelGrid>
          <p:commandLink ajax="true" update="mainform" process="@all" value="ok" actionListener="#{Bean.listenerMethod}" oncomplete="Testing.hide()"/>
      </h:form>
    </p:dialog>
</h:form>

谢谢

相关问题