Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Jsp p:menuitem未调用操作侦听器_Jsp_Primefaces - Fatal编程技术网

Jsp p:menuitem未调用操作侦听器

Jsp p:menuitem未调用操作侦听器,jsp,primefaces,Jsp,Primefaces,我有一个菜单,看起来像: <h:form> <p:menu> <p:menuitem value="One" actionListener="#{tabsVO.changeTab(1)}" update="tabView"/> <p:menuitem value="Two" actionListener="#{tabsVO.changeTab(2)}" update="tabView"/>

我有一个菜单,看起来像:

<h:form>
    <p:menu>
        <p:menuitem value="One" actionListener="#{tabsVO.changeTab(1)}" update="tabView"/>
        <p:menuitem value="Two" actionListener="#{tabsVO.changeTab(2)}" update="tabView"/>                              
        <p:menuitem value="Three" actionListener="#{tabsVO.changeTab(3)}" update="tabView"/>
    </p:menu>
</h:form>

一切看起来都很好,但是没有调用
操作侦听器
,单击菜单项时也不会发生任何事情

所以,当我调用错误的方法时,看起来像是这样

将bean方法从

 public void setCurrentTab(int currentTab) {
     this.currentTab = currentTab;
 } 

解决了这个问题

经过几个小时的挣扎,我终于明白了为什么这不起作用

默认情况下,
actionListener
需要一个名为
changeTab(longcurrenttab)
的方法,但我的bean中有
changeTab(intcurrenttab)
。所以,我基本上是想调用一个不存在的方法。 框架没有抛出任何错误,可能是因为默认情况下
p:menuitem
使用
ajax
。只有当我在menuitems上显式设置
ajax=“false”
时,我才开始得到错误,它说
“方法不存在”

我现在已经两次落入这个陷阱,浪费了很多时间去弄清楚它。把这个放在这里,这样可以帮助别人

 public void setCurrentTab(int currentTab) {
     this.currentTab = currentTab;
 } 
 public void setCurrentTab(Long currentTab) {
     this.currentTab = currentTab.intValue();
 }