【问题标题】:show panel when button is pressed按下按钮时显示面板
【发布时间】:2012-10-05 20:06:47
【问题描述】:

我在 primefaces 中有一个按钮和一个面板。我希望面板在按下按钮时可见。我怎样才能用primefaces做到这一点?

我有密码

        <p:commandButton value="Search" ajax="false"
        actionListener="#{myBean.searchPatients}" onclick="panelwv.show();">
    </p:commandButton>
    <p:panel widgetvar="panelwv" visible="false" closable="true" toggleable="true" >

但它不起作用

【问题讨论】:

    标签: button primefaces panel


    【解决方案1】:

    你的代码有错别字,你需要的属性是widgetVar:

    <p:commandButton value="Search" ajax="false"
        actionListener="#{myBean.searchPatients}" onclick="panelwv.show();">
    </p:commandButton>
    <p:panel widgetVar="panelwv" visible="false" closable="true" toggleable="true"/>
    

    如果您根本不想渲染您的面板,您应该考虑使用组件的rendered 属性。

    【讨论】:

    • 如果我想在 searchPatients 方法完成时显示面板,我应该更改什么??
    • 在这种情况下,您需要等待搜索完成,然后打开面板。 oncomplete="panelwv.show();"。您还应该更改ajax="true",我不确定这应该如何与ajax="false" 一起工作。
    • 使用 ajax="true" 面板中的元素不是从我的 bean 计算的,而使用 ajax="false" 面板根本不会出现
    • 由于这些 cmets 中讨论的问题不再是关于“按下按钮时显示面板”,我建议您发布一个新问题并留下这个问题的正确答案。
    • 无论如何,面板元素没有在 bean 中计算的事实可能意味着您没有在 bean 中计算这些值。如果您认为情况并非如此,请针对您的具体问题发布一个新问题。另请参阅我之前的评论。
    【解决方案2】:

    您可以为此使用对话框。你也可以看看这个

    https://www.primefaces.org/showcase/ui/overlay/dialog/basic.xhtml

    <p:commandButton value="Search" ajax="false"
    actionListener="#{myBean.searchPatients}" oncomplete="PF('dlg1').show();">
    </p:commandButton>
    <p:dialog header="Basic Dialog" widgetVar="dlg1" minHeight="40">
    <p:panel  visible="false" closable="true" toggleable="true"/>
    </p:dialog>
    

    【讨论】:

      猜你喜欢
      • 2023-01-11
      • 2014-02-15
      • 1970-01-01
      • 2012-05-06
      • 2016-07-03
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多