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/manhattan to view the demos which is exactly same as the live version.

Layout

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

<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/manhattan-layout folder, simply copy the manhattan-layout folder to your %WEB-APP-FOLDER%/resources folder so that final path would be %WEB-APP-FOLDER%/resources/manhattan-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 and theme configuration refer to this bean to dynamically change their behavior such as menu mode or theme. This bean is not necessary to run the Manhattan 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.theme}.css" library="manhattan-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-teal-yellow.css" library="manhattan-layout" />   

Similarly PrimeFaces theme can be changed dynamically.

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>manhattan-#{guestPreferences.theme}</param-value>
</context-param>

Source code of GuestPreferences.

public class GuestPreferences implements Serializable {

    public enum LayoutMode {
        SLIM,
        STATIC,
        OVERLAY,
        HORIZONTAL,
        TOGGLE
    };
        
    private String theme = "teal-yellow";

    private LayoutMode layoutMode = LayoutMode.SLIM;

    private boolean lightMenu = true;
                            
    public String getTheme() {		
        return theme;
    }
    
    public void setTheme(String theme) {
        this.theme = theme;
    }
    
    public LayoutMode getLayoutMode() {		
        return layoutMode;
    }
    
    public void setLayoutMode(LayoutMode layoutMode) {
        this.layoutMode = layoutMode;
    }

    public void updateLayoutMode(String mode) {
        this.layoutMode = LayoutMode.valueOf(mode);
    }

    public boolean isLightMenu() {
        return this.lightMenu;
    }

    public void setLightMenu(boolean value) {
        this.lightMenu = value;
    }
    
    public String getLayoutStyleClass() {
        String layoutStyleClass;
        switch(this.layoutMode) {
            case SLIM:
                layoutStyleClass = "layout-slim";
            break;

            case STATIC:
                layoutStyleClass = "layout-static";
            break;

            case OVERLAY:
                layoutStyleClass = "layout-overlay";
            break;

            case HORIZONTAL:
                layoutStyleClass = "layout-horizontal";
            break;

            case TOGGLE:
                layoutStyleClass = "layout-toggle";
            break;

            default:
                layoutStyleClass = "layout-slim";
            break;
        }

        if(this.lightMenu) {
            layoutStyleClass += " layout-light";
        }

        return layoutStyleClass;
    }
}

Theme

Manhattan provides 15 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 "manhattan-green". Full list of available themes are;

  • primefaces-manhattan-blue-grey
  • primefaces-manhattan-blue-orange
  • primefaces-manhattan-cyan-deeporange
  • primefaces-manhattan-darkpink-cyan
  • primefaces-manhattan-deeppurple-teal
  • primefaces-manhattan-green-orange
  • primefaces-manhattan-green-pink
  • primefaces-manhattan-green-purple
  • primefaces-manhattan-indigo-purple
  • primefaces-manhattan-indigo-yellow
  • primefaces-manhattan-orange-cyan
  • primefaces-manhattan-orange-indigo
  • primefaces-manhattan-pink-cyan
  • primefaces-manhattan-pink-teal
  • primefaces-manhattan-teal-yellow

A custom theme can be developed by the following steps.

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

Here are the variables required to create a theme.

$primaryColor:#147df0;
$primaryTextColor:#ffffff;
$primaryDarkColor:#1165c2;
$inputFocusBorderColor:#77aeeb;
$highlightBgColor:#ffaa00;
$highlightTextColor:#ffffff;
$datableEvenRowBgColor:#fdfafc;
$datatableHoverBgColor:#e3e1e2;

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

An example sass command to compile the css would be;

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

Layout customization is similar to theme method.

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

$sidebarTopStartBgColor:#3d72b4;
$sidebarTopEndBgColor:#525252;
$sidebarAnchorColor:#ffffff;
$menuitemActiveColor:#3D72B4;
$rootMenuitemActiveIconColor:#ffffff;
$menuitemBadgeBgColor:#7f7f7f;
$menuitemBadgeTextColor:#ffffff;
$horizontalLayoutTopbarTextColor:#ffffff;
$horizontalLayoutTopbarTextHoverColor:#BDD0E7;

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

$fontFamily:"Source Sans Pro","Helvetica Neue",sans-serif;
$fontSize:14px;
$textColor:#434560;
$textSecondaryColor:lighten($textColor,25%);
$borderRadius:2px;
$dividerColor:#d8dae2;
$transitionDuration:.3s;

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

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

@import './common';

$bodyBgColor:#f4f3f8;

//topbar
$topbarBgColor:#ffffff;
$topbarIconColor:#b6b7c2;
$topbarIconHoverColor:#7f8087;
$topbarIconActiveColor:#48494d;
$topbarInputBorderColor:#d8dae2;
$topbarSubmenuHoverBgColor:#f1f2f7;
$topbarMobileMenuBgColor:#ffffff;

//dark sidebar - default
$sidebarBgColor:#2c2d3c;
$menuitemIconBgColor:#1d1d26;
$menuitemTextColor:#d9dae3;
$menuitemHoverBgColor:#1d1d26;
$submenuitemHoverBgColor:#242430;
$activeMenuitemBgColor:#17171e;
$submenuBgColor:#17171e;

//light sidebar
$lightSidebarBgColor:#f2f2f7;
$lightSidebarMenuitemIconBgColor:#d9d9de;
$lightSidebarMenuitemTextColor:#575867;
$lightSidebarMenuitemHoverBgColor:#d9d9de;
$lightSidebarSubmenuitemHoverBgColor:#d9d9de;
$lightSidebarActiveMenuitemBgColor:#ffffff;
$lightSidebarSubmenuBgColor:#ffffff;

//misc
$rightPanelBgColor:#ffffff;
$mobileBreakpoint:1280px;
$contentMobileMaskBgColor:#ffffff;

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

@import './common';

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

/* Error */
$errorColor:#f28a8b;

/* Headers */
$headerPadding:6px 12px;
$headerHoverBgColor:#f1f2f7;

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

/* Forms */
$inputBgColor:#ffffff;
$inputPadding:6px;
$inputBorderColor:#b6b7c2;
$inputHoverBorderColor:#7f8087;

//groups
$inputGroupBorderColor:#b6b7c2;
$inputGroupBgColor:#ffffff;
$inputGroupTextColor:$textColor;
$inputGroupIconColor:$textSecondaryColor;
$inputGroupAddonMinWidth:2*$fontSize;
$checkboxWidth:20px;
$checkboxHeight:20px;

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

/* List Items */
$listItemPadding:6px 12px;
$listItemHoverBgColor:#f1f2f7;
$listItemHoverTextColor:#434560;

/* Messages */
$infoMessageBgColor:#a8cef8;
$infoMessageTextColor:#434560;
$warnMessageBgColor:#f7e9b9;
$warnMessageTextColor:#434560;
$errorMessageBgColor:#f9bbbc;
$errorMessageTextColor:#434560;
$fatalMessageBgColor:#b6b7c2;
$fatalMessageTextColor:#434560;

/* Data */
$datatableCellBorderColor:#dbe1e6;

/* TabView */
$tabHeaderPadding:8px 12px;

/* Panel */
$panelContentBorderColor:#DCE1E7;

Menu

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

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

<pm:menu>
</pm:menu>

Menu has 5 modes with 2 color alternatices. Layout wrapper element in template.xhtml is used to define which mode to use by adding specific classes.

  • "layout-slim": Slim menu
  • "layout-static": Static menu
  • "layout-overlay": Overlay menu
  • "layout-horizontal": Horizontal menu
  • "layout-toggle": Toggle menu
<div class="layout-wrapper layout-horizontal">
...
</div>

Default color scheme of the menu is dark and adding "layout-light" style class to the .layout-wrapper enables light mode.

<div class="layout-wrapper layout-overlay layout-light">
...
</div>

Layout mode can be dynamic using an EL expression as well, refer to GuestPreferences.java for an example.

<div class="layout-wrapper layout-slim layout-light">
...
</div>

Icons

Manhattan 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

Manhattan 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 /manhattan-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 Manhattan, 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.2 to 2.0.0

  • Update layout.js and layout css files
  • Update all xhtml files under WEB-INF for the new template.
  • 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 to 1.0.1

  • Update _exception.scss files
  • Replace theme jar with new jar
Wednesday
Jan 26

Weather

New York, USA

21℃
  • Thursday 24
  • Friday 19
  • Saturday 15
  • Sunday 24
  • Monday 21
  • Tuesday 20