jsfjsf-2primefacesprimefaces-mobile

How to lay out buttons in a PrimeFaces Mobile page?


I want to create a mobile web page (based on PrimeFaces Mobile), which looks like this:

Image 1

An image and underneath it - two buttons.

I wrote following xhtml page for that:

<!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>

But instead I get this view:

Image 2

How can I change my xhtml file to get the desired layout?


Solution

  • Simplify your <p:panelGrid> you don't need the <p:row> and <p:column>.

    <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>
    

    or all your really have to change is your panelGrid columns from 2 to 1:

    <p:panelGrid columns="1">
    

    Each JSF component in your <p:panelGrid> will create a new column based on the number of specified in the columns attribute.

    Examples:

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

    enter image description here

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

    enter image description here