【问题标题】:How to lay out buttons in a PrimeFaces Mobile page?如何在 PrimeFaces Mobile 页面中布置按钮?
【发布时间】:2015-01-02 03:55:31
【问题描述】:

我想创建一个移动网页(基于 PrimeFaces Mobile),如下所示:

图像及其下方 - 两个按钮。

我为此编写了以下 xhtml 页面:

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

<f:view renderKitId="PRIMEFACES_MOBILE"/>

<h:head>

</h:head>

<f:event listener="#{main.loadFirstImage}" type="preRenderView" />

<h:body id="body">

    <pm:page id="page">
        <pm:header title="myapp">
        </pm:header>

        <pm:content id="content">
            <h:form>
                <p:panelGrid columns="2">
                    <p:row>
                        <p:column colspan="2">
                            <p:graphicImage id="image" rendered="false" value="#{main.currentImage()}"
                                            cache="false">
                            </p:graphicImage>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="1">
                            <p:commandButton id="hotButton"
                                             value="Button 1"/>

                        </p:column>
                        <p:column colspan="1">
                            <p:commandButton id="notButton"
                                             value="Button 2"/>

                        </p:column>
                    </p:row>
                </p:panelGrid>
            </h:form>
        </pm:content>

        <pm:footer title="m.myapp.info"></pm:footer>
    </pm:page>
</h:body>

</html>

但是我得到了这个观点:

如何更改我的 xhtml 文件以获得所需的布局?

【问题讨论】:

    标签: jsf jsf-2 primefaces primefaces-mobile


    【解决方案1】:

    简化您的&lt;p:panelGrid&gt;,您不需要&lt;p:row&gt;&lt;p:column&gt;

    <p:panelGrid columns="1">
        <p:graphicImage id="image"></p:graphicImage>
        <p:panelGrid columns="2">
           <p:commandButton id="hotButton" value="Button 1"/>
           <p:commandButton id="notButton" value="Button 2"/>
        </p:panelGrid>
     </p:panelGrid>
    

    或者你真正需要改变的只是你的 panelGrid 列从 2 到 1:

    <p:panelGrid columns="1">
    

    &lt;p:panelGrid&gt; 中的每个 JSF 组件都将根据 columns 属性中指定的数量创建一个新列。

    例子:

    <p:panelGrid columns="1">
        <h:outputText value="1" />
        <h:outputText value="2" />
    </p:panelGrid>
    

    <p:panelGrid columns="2">
         <h:outputText value="1" />
         <h:outputText value="2" />
    </p:panelGrid>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多