【问题标题】:primefaces tab on clickPrimefaces 选项卡点击
【发布时间】:2013-07-18 13:24:52
【问题描述】:

我有一个这样的 primefaces 选项卡视图:

<p:tabView id="tabView">  
    <p:tab id="tab1" title="Godfather Part I">  
        This tab has static content.
    </p:tab>  

    <p:tab id="tab2" title="Godfather Part II">  
        this tab has a datatable whose  
    </p:tab>  
</p:tabView>

现在,我想做的是,当用户单击 tab2 时触发 managedbean 方法。我可以在 tabView 的 tabchange 事件上添加一个动作监听器,但这也会在点击 tab1 时触发该方法。如何仅在单击 tab2 时触发方法?

【问题讨论】:

    标签: primefaces tabs onclick


    【解决方案1】:

    点击您的 tabView 的每个选项卡时将调用动作侦听器。 但是你可以通过像这样的条件块来控制你的动作监听器。 这是一个例子:

    <p:tabView id="tabView" dynamic="true">
    
        <p:ajax event="tabChange" listener="#{Bean.onTabChange}" update=":messages" />
        <p:tab id="tab1" title="#{userLbl['notification.headerIncoming']}">
        <p:tab id="tab2" title="#{userLbl['notification.headerOutgoing']}">
    </p:tabView>
    

    动作监听器:

    public void onTabChange(TabChangeEvent event) {
    
       if (event.getTab().getId().equals("tab1")) {
           //Your actions for tab1
       } else if((event.getTab().getId().equals("tab2")) {
         //Your actions for tab2
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-23
      • 2013-11-29
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多