官术网_书友最值得收藏!

  • PrimeFaces Theme Development
  • Andy Bailey Sudheer Jonna
  • 430字
  • 2021-07-09 21:12:25

Creating a Mini Showcase page

In the following section, we will create pages with PrimeFaces components so that we can see how themes affect their look and feel. It is a mini showcase because we will not add every available PrimeFaces component.

Perform the following steps to create a Mini Showcase page:

  1. Right-click on the chapter2 folder and move the mouse over New. Select the Facelets Template Client option and name it morecomponents.

    Tip

    For the book, we are developing a project that will be used to show off our own theme. This project is available in a GIT repository (see the Preface for the link). The file names that I used are those that I used in that project. You are of course free to choose your own filenames.

  2. Choose chaptersTemplate as the page template and click on Finish.
  3. Add an appropriate page title in the define name="title" tag. I used the following:
    <ui:define name="title">
      A mini ShowCase of PrimeFaces components
    </ui:define>
  4. Then, add the following code in the content define tag. I included the define tag for completeness; the relevant code is highlighted:
    <ui:define name="content">
    
      <h:form id="mainForm">
        <h:panelGrid columns="2">
          <p:outputLabel value="PrimeFaces Input:"/><p:inputText/>
          <p:outputLabel value="PrimeFaces Spinner"/><p:spinner/>
          <p:outputLabel value="PrimeFaces Panel"/>
          <p:panel header="An simple panel" toggleable="true"         toggleTitle="Click to close/open">
            <p:commandButton value="Show dialog" onclick=           "PF('simpleDialog').show();"process="@this"/>
          </p:panel>
        </h:panelGrid>
        <p:dataList value="#{themesService.themes}" var="theme">
          #{theme}
        </p:dataList>
        <p:dialog id="dialog1" widgetVar="simpleDialog"       modal="true">
          <p:commandButton id="closeDialog" value="Close the         dialog" onclick="PF('simpleDialog').hide();"         process="@this"/>
        </p:dialog>
      </h:form>
    
    </ui:define>

    There is no need to go into the different components here. The important thing is that we have a set of components with different features that will look different according to the theme currently being used.

  5. Save the file and open chaptersTemplate. Then, add a link to the page that we just created by adding the following highlighted code to the Chapter 2 submenu:
    <p:submenu id="chapter2" label="Chapter 2">
      <p:menuitem id="c2difference" value="Differences" url="/chapter2/difference.xhtml"/>
      <p:menuitem id="c2morecomponents" value="Mini Showcase" url="/chapter2/morecomponents.xhtml"/>
    </p:submenu>
  6. Now, save the changes that we made. To make sure that the project runs correctly, we need to clean and build the project before running it again.
  7. When the project is up and running again, use the Chapter 2 submenu to navigate to the Mini Showcase page. You will see something similar to the following screenshot:
    Creating a Mini Showcase page

In the preceding screenshot, the afternoon theme was chosen. This is a good opportunity if you wish to try out the different available themes to see how things look.

The Show dialog button actually opens a modal dialog box, which contains a button to close the dialog box again. Try it to see how the dialog box looks. Note that we cannot change the current theme with the dialog box left open. This is because a modal dialog box masks the rest of the page and only allows interaction with the dialog box itself. We use a modal dialog box here because of the pane used to mask the rest of the page. It normally has a translucent background, but this can change depending on the theme.

主站蜘蛛池模板: 绩溪县| 揭阳市| 娱乐| 四子王旗| 蛟河市| 亳州市| 马鞍山市| 固阳县| 泸水县| 远安县| 德保县| 华安县| 营口市| 德钦县| 鸡泽县| 慈利县| 广平县| 淮北市| 肥乡县| 洛阳市| 基隆市| 镇远县| 昆山市| 白城市| 武胜县| 定西市| 东山县| 衡阳市| 来宾市| 海原县| 凉山| 涞源县| 卢湾区| 双峰县| 腾冲县| 平昌县| 南华县| 伊通| 全南县| 汨罗市| 揭阳市|