如何在p:accordionPanel中标识用于控制器功能的选项卡? [英] How to ID a tab inside p:accordionPanel for controller functions?

查看:58
本文介绍了如何在p:accordionPanel中标识用于控制器功能的选项卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考我之前的问题.

我需要能够识别与p:accordionPanel中的每个选项卡(或行)关联的实体.例如.如果这些行对应于ID为1、2、3的实体,那么当我单击每个选项卡时,我想触发一个事件,该事件将由使用该选项卡ID的控制器处理. IOW,我需要每个选项卡和控制器之间的引用指针.

I need to be able to identify the entity associated with each tab (or row) in a p:accordionPanel. E.g. if the rows correspond to entities whose IDs are 1, 2, 3, when I click on each tab, I want to trigger an event to be processed by the controller that uses the ID of that tab. IOW, I need a reference pointer between each tab and the controller.

从我之前的帖子中可以看到,ID属性无效.如何在视图中的每个选项卡和控制器之间建立身份引用?

The ID atribute, as can be seen from my previous post, did not work. How can I establish identity reference between each tab in the view and the controller?

推荐答案

您可以尝试使用AccordionPanel的activeIndex属性,该属性是活动选项卡的索引.

You can try to use the activeIndex attribute of the accordionPanel which is the index of the active tab.

<p:accordionPanel activeIndex="#{playgroundController.activeIndex}">
    <p:ajax event="tabChange" listener="#{playgroundController.onTabChange()}" />
    <p:tab title="Godfather Part I">
        <h:panelGrid columns="2" cellpadding="10">
            <h:outputText
                value="The story begins as Don Vito Corleone..." />
        </h:panelGrid>
    </p:tab>
    <p:tab title="Godfather Part II">
        <h:panelGrid columns="2" cellpadding="10">
            <h:outputText value="Francis Ford Coppola's legendary..." />
        </h:panelGrid>
    </p:tab>
    <p:tab title="Godfather Part III">
        <h:panelGrid columns="2" cellpadding="10">
            <h:outputText value="After a break of more than 15 years..." />
        </h:panelGrid>
    </p:tab>
</p:accordionPanel>

Bean:

private String activeIndex = "";


public void onTabChange() {
    logger.debug("onTabChange : activeIndex : {}  ", activeIndex);
}

在打印的一个标签上单击时,

While clicking on one of the tabs it prints:

09:38:55,822 DEBUG [PlaygroundController] onTabChange : activeIndex : 0  
09:38:56,625 DEBUG [PlaygroundController] onTabChange : activeIndex : 1  
09:38:57,426 DEBUG [PlaygroundController] onTabChange : activeIndex : 2  

这篇关于如何在p:accordionPanel中标识用于控制器功能的选项卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆