Emma Davis

Layout

Paradise utilizes JSF templating APIs and provides a main template.xhtml along with additional topbar, menu, footer fragments for the base layout. These xhtml files must be placed under WEB-INF folder and client pages should reference the template.xhtml as their template. Provided empty.xhtml is a sample content page using the main template.xhtml that defines "content" as the main ui:define placeholder. By default template defines 3 placeholders (page title, header content and actual content)to insert content and you can add more as per your requirements.

Sample page below uses the main template from Paradise.

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/template.xhtml">
                
    <ui:define name="title">Test Page</ui:define>

    <ui:define name="content">
        Content goes here
    </ui:define>
</ui:composition>

Other required resources are the css, js and images that are located inside resources/paradise-layout folder, simply copy the paradise-layout folder to your %WEB-APP-FOLDER%/resources folder so that final path would be %WEB-APP-FOLDER%/resources/paradise-layout/. Please refer to demo app or maven project of the demo app as the reference.

GuestPreferences Bean

GuestPreferences is a simple session scoped bean to keep the user customizations of the layout, template xhtml files refer to this bean to dynamically change their behavior such as menu mode or theme. This bean is not necessary to run the Paradise and only used for demo purposes. For example template.xhtml includes layout color depending on a user preference using an EL expression.

<h:outputStylesheet name="css/layout-#{guestPreferences.layout}.css" library="paradise-layout" />   

In your application, you may also need a similar bean to make the template dynamic or choose a static color with;

<h:outputStylesheet name="css/layout-blue.css" library="paradise-layout" />   

Source code of GuestPreferences.

public class GuestPreferences implements Serializable {
        
    private String theme = "blue";
    
    private String layout = "default";
            
    private boolean overlayMenu = false;
    
    private boolean slimMenu = false;
    
    private boolean darkMenu = false;
                
	public String getTheme() {		
		return theme;
	}
    
    public String getLayout() {		
        return layout;
    }
    
	public void setTheme(String theme) {
		this.theme = theme;
	}
    
    public void setLayout(String layout) {
		this.layout = layout;
	}
        
    public boolean isOverlayMenu() {
        return this.overlayMenu;
    }
    
    public void setOverlayMenu(boolean value) {
        this.overlayMenu = value;
        this.slimMenu = false;
    }
    
    public boolean isSlimMenu() {
        return this.slimMenu;
    }
    
    public void setSlimMenu(boolean value) {
        this.slimMenu = value;
    }
    
    public boolean isDarkMenu() {
        return this.darkMenu;
    }
    
    public void setDarkMenu(boolean value) {
        this.darkMenu = value;
    }
}

Theme

Paradise provides 7 PrimeFaces themes out of the box, setup of a theme simple as including the theme jar in your classpath and defining primefaces.THEME context parameter in web.xml such as "primefaces-paradise-green". Full list of available themes are;

  • primefaces-paradise-blue
  • primefaces-paradise-deeppurple
  • primefaces-paradise-green
  • primefaces-paradise-orange
  • primefaces-paradise-purple
  • primefaces-paradise-turquoise
  • primefaces-paradise-lime

A custom theme can be developed by the following steps.

  • Create a custom theme folder such as primefaces-paradise-myown under webapp/resources and place an empty theme.scss inside.
  • Copy the sass folder from the distribution to webapp/resources.
  • Define the variables listed below and import the /sass/theme/_theme.scss file.
  • Build the scss to generate css.
  • Set primefaces.THEME context parameter as paradise-myown
  • Either bundle the css in a jar file or serve from webapp/resources/primefaces-paradise-myown folder

Here are the variables required to create a theme.

$primaryColor:#3984b8;
$primaryTextColor:#ffffff;

@import '../sass/theme/_theme';

An example sass command to compile the css would be;

sass src/main/webapp/resources/primefaces-paradise-myown/theme.scss src/main/webapp/resources/primefaces-paradise-myown/theme.css  --sourcemap=none

Watch mode is handy to avoid compiling everytime when a change is made, instead use the following command so that sass generates the file whenever you make a customization. This builds all css files whenever a change is made to any scss file.

sass -w src/main/webapp/resources/ --sourcemap=none

Same can also be applied to layout itself;

  • Choose a layout name such as layout-myown.
  • Create an empty file named layout-myown.scss inside resources/paradise-layout/css folder.
  • Copy the sass folder from the distribution to webapp/resources.
  • Define the variables listed below and import the /sass/layout/_layout.scss file.
  • Build the scss to generate css
  • Serve the css by importing it using a link tag or h:outputStylesheet.

Here are the variables required to create a layout

$primaryColor:#1976d2;
$primaryLightColor:#2196F3;
$primaryTextColor:#BBDEFB;
$primaryTextHoverColor:#E3F2FD;
$accentColor:#FFC107;
$accentLightColor:#FFECB3;
$accentTextColor:#000000;
$activeMenuItemTextColor:#1976d2;
$darkActiveMenuItemTextColor:#2196F3;
$darkMenuItemTextColor:#dee0e3;
$darkMenuItemInactiveTextColor:#757575;
$darkMenuItemHoverBgColor:#545454;
$darkSidemenuBgColor:#343434;
$darkMenuBgColor:#424242;

@import '../../sass/layout/_layout';

In case you'd like to customize common variables not theme colors, the _variables.scss is where the structural variables (e.g. font size, paddings) for the layout are defined.

/******************************/
/*           Common           */
/******************************/
$fontFamily:"Roboto","Helvetica Neue",sans-serif;
$fontSize:13px;
$textColor:#757575;
$textSecondaryColor:lighten($textColor,25%);
$borderRadius:2px;
$dividerColor:#dee4e9;

/******************************/
/*           Layout           */
/******************************/
$darkMenuTextColor:#ffffff;

/******************************/
/*           THEME            */
/******************************/
/* Icons */
$iconFontSize:13px;
$iconWidth:16px;

/* Error */
$errorColor:#e17576;

/* Headers */
$headerPadding:6px 12px;
$headerBgColor:#ffffff;
$headerTextColor:#757575;
$headerHoverBgColor:#dee4e9;
$headerBorderColor:#c7cdd1;
$headerIconColor:#757575;
$headerIconHoverColor:$primaryColor;

/* Contents */
$contentPadding:6px 12px;
$contentBorderColor:#c7cdd1;
$contentBgColor:#ffffff;

/* Forms */
$inputBgColor:#ffffff;
$inputPadding:5px;
$inputBorderColor:#bdc3c9;
$inputHoverBorderColor:#979ca0;

/* Buttons */
$buttonTextColor:#ffffff;
$toggleButtonBgColor:#c6cbcf;

/* List Items */
$listItemPadding:6px 12px;
$listItemHoverBgColor:#dee4e9;
$listItemHoverTextColor:#757575;

/* Messages */
$infoMessageBgColor:#a8c9e0;
$infoMessageTextColor:#393b3e;
$warnMessageBgColor:#f8eab9;
$warnMessageTextColor:#393b3e;
$errorMessageBgColor:#fac7c8;
$errorMessageTextColor:#393b3e;
$fatalMessageBgColor:#bdc3c9;
$fatalMessageTextColor:#393b3e;

/* Data */
$paginatorBgColor:#ffffff;
$paginatorHoverBgColor:#dee4e9;
$datableEvenRowBgColor:#f6f8f9;
$datatableHoverBgColor:#dee4e9;

/* Predefined Colors */
$blue:#3984b8;
$orange:#f6ac2b;
$purple:#7e8dcd;
$pink:#e175a0;
$turquoise:#39b8b6;
$green:#3eb839;
$red:#e17576;

Menu

Menu is a regular JSF component that supports PrimeFaces MenuModel API allowing both declarative and programmatic approaches.

xmlns:pv="http://primefaces.org/paradise"

<pv:menu>
</pv:menu>

Menu has 3 modes; static, overlay and slim. Layout wrapper element in template.xhtml is used to define which mode to use by adding specific classes. List below indicates the style classes for each mode.

  • Static: "layout-menu-static"
  • Overlay: "layout-menu-overlay"
  • Slim: "layout-menu-slim"

For example to create a static menu, the div element should be in following form;

<div class="layout-wrapper layout-menu-static">
    ...
</div>

Layout mode can be dynamic using an EL expression as well using an example bean called userPreferences.

<div class="layout-wrapper #{userPreferences.slimMenu ? 'layout-menu-slim' : (userPreferences.overlayMenu ? 'layout-menu-overlay' : 'layout-menu-static')}">
...
</div>

Icons

Paradise Layout uses font awesome icons for layout so enable font awesome support in PrimeFaces by setting primefaces.FONT_AWESOME context parameter in web.xml as true. If your PrimeFaces version does not have the font awesome integration, include the font-awesome manually in your application.

Card

Card is a section to group content and layout provides a built-in css for it. Apply .card style class to your container to use it. If the card has a title defined with h1 tag, add card-w-title to adjust paddings.

<div class="card">
    Content here
</div>

<div class="card card-w-title">
    <h1>Card with Title<h1>
    Content here
</div>

Grid CSS

Paradise uses new PrimeFaces Grid CSS (ui-g-*) throughout the samples, we strongly suggest using Grid CSS as your layout framework as it is well tested and supported by PrimeFaces. Grid CSS is automatically included on newer versions however if your PrimeFaces version is older than 5.3.14, add the provided grid.css file under /paradise-layout/css/ folder to your template manually.

Tips

  • Familiarity with SASS is required to make customizations to the layout and theme.
  • Demo application war and the maven project tag are included in distribution however you don't necessarily need them to install Paradise, the actual artifacts required are the layout zip file and the theme jar.
  • Sample demo application war includes the JSF libraries so it is suggested to remove them from the war file when you deploy to an appserver.
  • When running the maven project, you need to build the sass with (sass --update src/main/webapp/resources/ --sourcemap=none) command.

Migration Guide

1.0 to 1.0.1

  • Update layout css files
  • Replace theme jar with new jar