Getting Started

First of all, you'd need SASS to compile CSS, proceed to SASS Installation before beginning if you do not have SASS available in your command line.

Demo project has an integrated jetty plugin so running the sample is easy as building the css first followed by the mvn jetty:run command.

sass --update src/main/webapp/resources/ --sourcemap=none
mvn jetty:run

Navigate to http://localhost:8080/serenity to view the demos which is exactly same as the live version.

Template

Serenity utilizes JSF templating APIs and provides a main template.xhtml along with additional topbar, sidebar and 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 Serenity.

<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/serenity-layout folder, simply copy the serenity-layout folder to your %WEB-APP-FOLDER%/resources folder so that final path would be %WEB-APP-FOLDER%/resources/serenity-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 Serenity 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="serenity-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="serenity-layout" />

Source code of GuestPreferences.

public class GuestPreferences implements Serializable {

    private String layout = "moody";

    private String theme = "bluegrey";

    private boolean darkMenu;

    public String getTheme() {
    	return theme;
    }

    public void setTheme(String theme) {
    	this.theme = theme;
    }

    public String getLayout() {
        return layout;
    }

    public void setLayout(String layout) {
        this.layout = layout;
    }

    public boolean isDarkMenu() {
        return darkMenu;
    }

    public void setDarkMenu(boolean darkMenu) {
        this.darkMenu = darkMenu;
    }
}

Theme

Serenity provides 18 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-serenity-green". Full list of available themes are;

  • primefaces-serenity-amber
  • primefaces-serenity-blue
  • primefaces-serenity-bluegrey
  • primefaces-serenity-brown
  • primefaces-serenity-cyan
  • primefaces-serenity-deeporange
  • primefaces-serenity-deeppurple
  • primefaces-serenity-green
  • primefaces-serenity-grey
  • primefaces-serenity-indigo
  • primefaces-serenity-lightblue
  • primefaces-serenity-lime
  • primefaces-serenity-orange
  • primefaces-serenity-pink
  • primefaces-serenity-purple
  • primefaces-serenity-teal
  • primefaces-serenity-yellow

A custom theme can be developed by the following steps.

  • Create a custom theme folder such as primefaces-serenity-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 serenity-myown
  • Either bundle the css in a jar file or serve from webapp/resources/primefaces-serenity-myown folder

Here are the variables required to create a theme.

$primaryColor:#FFB300;
$primaryDarkColor:#FF8F00;
$primaryLightColor:#FFCA28;
$primaryLightestColor:#FFF8E1;
$primaryTextColor:#212121;
$accentColor:#E91E63;
$accentDarkColor: #C2185B;
$accentLightColor: #F06292;
$accentTextColor: #ffffff;

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

An example sass command to compile the css would be;

sass src/main/webapp/resources/primefaces-serenity-myown/theme.scss src/main/webapp/resources/primefaces-serenity-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

Layout

There are 27 layout colors in total with flat and special alternatives. Configuring a layout color is easy as adding the css file to the template.xhtml where the choice can be left to the user with an EL expression.

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

Creating a custom layout with the color scheme of your choice is similar to creating a custom theme.

  • Choose a layout name such as layout-myown.
  • Create an empty file named layout-myown.scss inside resources/serenity-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.

/* Sidebar */
$sidebarLogoBgColor:rgba(36,50,59,0.5);
$sidebarBgColor:#566e87;
$darkSidebarBgColor:#202d35;
$menuBgImage:'bg-moody';

/* Primary */
$primaryColor:#607D8B;
$primaryDarkColor:#496475;
$primaryLightColor:#90A4AE;
$primaryLightestColor:#E8EAF6;
$primaryTextColor:#ffffff;

/* Accent */
$accentColor:#7CB342;
$accentLightColor:#9CCC65;
$accentTextColor:#ffffff;

/* Topbar */
$topbarTextColor:#E8EAF6;
$topbarIconColor:#E8EAF6;

/* Submenu */
$submenuBgColor:rgba(255,255,255,0.2);
$darkSubmenuBgColor:rgba(255,255,255,0.15);

/* Default MenuItem */
$menuitemTextColor:#ffffff;
$menuitemIconTextColor:#ffffff;

/* Hover MenuItem */
$menuitemHoverBgColor:rgba(0,0,0,0.4);
$menuitemHoverTextColor:#ffffff;
$menuitemHoverIconTextColor:#ffffff;

/* Active MenuItem */
$menuitemActiveBgColor:#7CB342;
$menuitemActiveTextColor:#ffffff;
$menuitemActiveIconTextColor:#ffffff;
$subMenuitemActiveTextColor:#9CCC65;
$subMenuitemActiveIconTextColor:#9CCC65;

/* Dark Default MenuItem */
$darkMenuitemTextColor:#dee0e3;
$darkMenuitemIconTextColor:#dee0e3;

/* Dark Hover MenuItem */
$darkMenuitemHoverBgColor:#rgba(255,255,255,0.4);
$darkMenuitemHoverTextColor:#ffffff;
$darkMenuitemHoverIconTextColor:#ffffff;

/* Dark Active MenuItem */
$darkMenuitemActiveBgColor:#7CB342;
$darkMenuitemActiveTextColor:#ffffff;
$darkMenuitemActiveIconTextColor:#ffffff;
$darksubMenuitemActiveTextColor:#9CCC65;
$darksubMenuitemActiveIconTextColor:#9CCC65;

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

SASS Variables

In case you'd like to customize common variables, the _common.scss under sass variables folder is where the core variables (e.g. font size, paddings) for the layout are defined.

$fontSize:14px;
$fontFamily:"Roboto","Helvetica Neue",sans-serif;
$textColor:#212121;
$textSecondaryColor:#757575;
$lineHeight:18px;
$borderRadius:3px;
$dividerColor:#dbdbdb;
$dividerLightColor:#f8f8f8;
$transitionDuration:.3s;
$iconWidth:20px;
$iconHeight:20px;
$iconFontSize:20px;
$hoverBgColor:#e8e8e8;
$hoverTextColor:#000000;

/* Predefined Colors */
$blue:#147df0;
$pink:#ed3c76;
$green:#3e9018;
$red:#da2f31;
$orange:#ffb200;
$teal:#599597;
$purple:#633ea5;
$black:#000000;
$yellow:#ffd644;
$grayBgColor:#757575;

_layout.scss under variables define the shared variables of the layout.

@import './common';

$bodyBgColor:#F5F5F5;
$topbarSubmenuHoverBgColor:#f1f2f7;
$topbarMobileMenuBgColor:#ffffff;
$mobileBreakpoint:840px;
$contentMobileMaskBgColor:#424242;

Similarly _theme.scss files contains the shared variables of the PrimeFaces theme.

@import './common';

$headerPadding:8px 14px;
$headerTextColor:#ffffff;

$contentPadding:8px 14px;
$contentBorderColor:#d8d8d8;
$contentBgColor:#ffffff;

$inputBorderColor:#bdbdbd;
$inputInvalidBorderColor:#e62a10;
$inputBgColor:#ffffff;
$inputErrorTextColor:#e62a10;
$inputHeaderPadding:6px 10px;

$buttonTextColor:#ffffff;

$listItemPadding:6px 10px;

$radioButtonBorderColor:#757575;
$checkboxBorderColor:#757575;

$errorMessageFontSize:11px;
$errorMessageIconFontSize:13px;

$dataTableRowBgColorEven:#f4f4f4;
$paginatorPadding:6px 10px;
$menuitemPadding:6px 10px;

Menu

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

xmlns:ps="http://primefaces.org/serenity"

<ps:menu>
</ps:menu>

Menu has 3 modes; static, overlay and horizontal. Layout wrapper element in template.xhtml is used to define which mode to use by adding specific classes. Default is overlay and adding "layout-wrapper-static" enables static mode. The anchor icon at the top of the sidebar also toggles between overlay and static modes.

  • Static: "layout-wrapper layout-wrapper-static"
  • Overlay (Default): "layout-wrapper"
  • Horizontal: "layout-wrapper layout-menu-horizontal"

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

<div class="layout-wrapper #{guestPreferences.staticMenu ? 'layout-sidebar-static' ? ''}">
...
</div>

Dark and Light Menu

Each layout provides a dark menu alternative, default mode is light menu and adding "layout-sidebar-dark" style class to the sidebar element activates the dark mode. As with the layout itself, this can be made dynamic using an EL expression inside sidebar.xhtml.

<div class="layout-sidebar ">
...
</div>

RTL

Layout can be used in RTL orientation as well by adding "layout-rtl" to the "layout-wrapper" div in template.xhtml.

Grid CSS

Serenity 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 /serenity-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 Serenity, 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.6 to 2.0.0

  • Update SerenityMenu*.java
  • Replace theme jar with new jar

1.0.5 to 1.0.6

  • Update layout and theme css files
  • Update layout.js and SerenityMenu*.java
  • Replace theme jar with new jar

1.0.4 to 1.0.5

  • Update layout and theme css files
  • Update layout.js
  • Replace theme jar with new jar

1.0.3 to 1.0.4

  • Update layout.js and layout css files
  • Replace theme jar with new jar

1.0.2 to 1.0.3

  • Update layout.js and layout css files
  • Replace theme jar with new jar

1.0.1 to 1.0.2

  • Update layout-*.css files
  • Update theme jar and layout.js
  • Add new layout-*.css files