【问题标题】:Primefaces,how to collapse layoutUnit with another button?Primefaces,如何用另一个按钮折叠 layoutUnit?
【发布时间】:2012-10-01 16:01:06
【问题描述】:

我在 Mojarra-2.1.10 上使用 primefaces PrimeFaces-3.4,我的整页布局类似于 this。我如何在顶部制作一个按钮,它将折叠西 layoutUnit?

感谢您的帮助。

PS,早期假设可以这样写:

<layoutUnit position="west" widgetVar='westlayout'> ... </layoutUnit>

//button in the top
<button onlick="westlayout.collapse()"></button>

但不幸的是,layoutUnit 不存在 widgetVar 属性。

更新 1:找到 similar question,已尝试。对我不起作用,问题是具有更新属性的按钮找不到具有此类标识符的文本,我在一个 layoutUnit 中尝试,找到了标识符,但也没有用。

【问题讨论】:

    标签: java javascript layout jsf-2 primefaces


    【解决方案1】:

    根据 Layout Client Side API,您可以通过 layout widgetWar 切换 layoutUnit:

    <p:layout fullPage="true" widgetVar="layoutWdgt">
        <p:layoutUnit position="north" size="100" header="Top" resizable="true" closable="true" collapsible="true">
            <h:form>
                <p:commandButton value="Toggle" onclick="layoutWdgt.toggle('west')"/>
            </h:form>
        </p:layoutUnit>
    
        ....
    
        <p:layoutUnit position="west" size="200" header="Left" resizable="true" closable="true" collapsible="true">
            <h:form>
                <h:outputText value="West Layout unit"/>
            </h:form>
        </p:layoutUnit>
        <p:layoutUnit position="center">
            <h:outputText value="Center Layout unit"/>
        </p:layoutUnit>
    </p:layout>
    

    已编辑

    从 PrimeFaces 4 开始,id 映射仍受支持,但已弃用,取而代之的是 PF('XXX')

    对于 PrimeFaces 5.0 及以上版本,您需要使用 PF widgetVar 来调用客户端 API。因此,您需要使用 PF('layoutWdgt').toggle('west')

    而不是使用 layoutWdgt.toggle('west') 切换西布局单元

    【讨论】:

    【解决方案2】:

    使用 Primefaces 6.1:

    <p:layout style="min-width:400px;min-height:200px;" widgetVar="layoutWdgt">
        <p:layoutUnit position="west" size="100" minSize="40" maxSize="200" collapsible="true">
            West
             <p:commandButton value="Collapse" onclick="PF('layoutWdgt').toggle('west')"/>
        </p:layoutUnit>
        <p:layoutUnit position="center">
            Center
        </p:layoutUnit>
    </p:layout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-11
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 2019-09-27
      • 1970-01-01
      相关资源
      最近更新 更多