首页 > 解决方案 > p:accordionPanel 在第一个选项卡上进行投票

问题描述

<p:poll>我默认禁用autoStart="false".
现在我有一个由 commandButton 打开的对话框,其中包含以下示例代码:

<h:body>
    <h:form>

        <p:commandButton value="Open Dialog" oncomplete="PF('sampleDialog').show();PF('w_poll').start();"/>

        <p:dialog header="Sample Dialog" height="300" width="400" widgetVar="sampleDialog" resizable="false" onHide="PF('w_poll').stop();">
            <p:accordionPanel>
                <p:ajax event="tabChange" oncomplete="PF('w_poll').start();"/>
                <p:tab title="First">
                    <h:panelGroup id="firstGroup">
                        <p:poll interval="1"
                                id="firstPoll"
                                widgetVar="w_poll"
                                update="firstLabel"
                                async="true"
                                autoStart="false"
                                global="false"
                                listener="#{firstCounter.init}"/>
                        <p:outputLabel value="#{firstCounter.number}" id="firstLabel"/>
                    </h:panelGroup>
                </p:tab>
                <p:tab title="Second">
                    <h:panelGroup id="secondGroup">
                        <p:poll interval="3"
                                id="secondPoll"
                                widgetVar="w_poll"
                                update="secondLabel"
                                async="true"
                                autoStart="false"
                                global="false"
                                listener="#{secondCounter.init}"/>
                        <p:outputLabel value="#{secondCounter.number}" id="secondLabel"/>
                    </h:panelGroup>
                </p:tab>
                <p:tab title="Third">
                    <h:panelGroup id="thirdGroup">
                        <p:poll interval="5"
                                id="thirdPoll"
                                widgetVar="w_poll"
                                update="thirdLabel"
                                async="true"
                                autoStart="false"
                                global="false"
                                listener="#{thirdCounter.init}"/>
                        <p:outputLabel value="#{thirdCounter.number}" id="thirdLabel"/>
                    </h:panelGroup>
                </p:tab>
            </p:accordionPanel>
        </p:dialog>
    </h:form>
</h:body>

注意:您可以看到民意调查在对话框显示开始并在隐藏时停止。
这是我的豆子:

public abstract class AbstractBean implements Serializable {

    private int number;

    public void counter(int sleepTime) {
        sleep(sleepTime);
        this.number = number + 1;
    }

    public int getNumber() {
        return number;
    }

    private static void sleep(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}       

现在用这个抽象实现三个bean:

@Named
@ViewScoped
public class FirstCounter extends AbstractBean {

    @PostConstruct
    public void init() {
        counter(1000);
    }
}

另一个:

@Named
@ViewScoped
public class SecondCounter extends AbstractBean {

    @PostConstruct
    public void init() {
        counter(3000);
    }
}       

另一个:

@Named
@ViewScoped
public class ThirdCounter extends AbstractBean {

    @PostConstruct
    public void init() {
        counter(5000);
    }
}

我有两个问题:
1)打开对话框后手风琴面板的第一个选项卡没有启动计数器。
2)更改选项卡事件不起作用。我想启动同一个选项卡的计数器。

标签: jsfprimefacesjsf-2.2

解决方案


推荐阅读