Primefaces使用另一个按钮折叠LayoutUnit

时间:2014-08-11 08:58:07

标签: jquery jsf-2 primefaces

我一直在尝试添加一些功能来扩展/折叠primeface中的layoutUnit,但我似乎无法让它工作。我在这里找到了另外两个答案,但它们都不适合我:

Primefaces, how to collapse layoutUnit using some script or jquery function

Primefaces,how to collapse layoutUnit with another button?

例如,我测试了以下代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:pf="http://primefaces.org/ui">

    <h:head>

    </h:head>
    <h:body>
        <pf:layout fullPage="true" widgetVar="layoutWdgt">
            <pf:layoutUnit position="north" size="100" header="Top" resizable="true" closable="true" collapsible="true">
                <h:form>
                    <pf:commandButton value="Toggle" onclick="layoutWdgt.toggle('west')"/>
                </h:form>
            </pf:layoutUnit>

            <pf:layoutUnit position="west" size="200" header="Left" resizable="true" closable="true" collapsible="true">
                <h:form>
                    <h:outputText value="West Layout unit"/>
                </h:form>
            </pf:layoutUnit>
            <pf:layoutUnit position="center">
                <h:outputText value="Center Layout unit"/>
            </pf:layoutUnit>
        </pf:layout>
    </h:body>
</html>

这不起作用。西部layoutunit标题上的默认展开折叠图标展开/折叠西部layoutUnit,但是&#39; Toggle&#39;北部layoutUnit中的按钮似乎只是重新加载页面而不改变任何东西。

这是使用primefaces 5.任何想法?

1 个答案:

答案 0 :(得分:2)

好的,因为您需要使用'PF'功能来获取布局小部件,即:

 <pf:commandButton value="Toggle" onclick="PF('layoutWdgt').toggle('west')"/>

虽然在我指定的其他帖子中没有提及,但我只能假设在以后的PrimeFaces版本中这是必要的。