Skip to content

antoniocaccamo/admin-template

 
 

Repository files navigation

Admin Template

A JSF fully responsive admin template based on Primefaces, Admin LTE and Bootstrap.

1. Usage

First include it in your classpath:

<dependency>
    <groupId>com.github.adminfaces</groupId>
    <artifactId>admin-template</artifactId>
    <version>version</version>
</dependency>

Admin template will bring the following transitive dependencies:

<dependency>
    <groupId>com.github.adminfaces</groupId>
    <artifactId>admin-theme</artifactId>
    <version>version</version>
</dependency>
<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>6.0</version>
</dependency>

<dependency>
    <groupId>org.omnifaces</groupId>
    <artifactId>omnifaces</artifactId>
    <version>2.1</version>
</dependency>

Of cource you can override them in your pom.xml as needed.

Now you can use it in your JSF pages:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="/admin.xhtml"> (1)

    <ui:define name="head">
        <title>Admin Starter</title>
    </ui:define>

    <ui:define name="logo-lg">
        Admin Starter
    </ui:define>

    <ui:define name="logo-mini">
        Admin
    </ui:define>

    <ui:define name="menu">
        <ul class="sidebar-menu">
            <li>
                <p:link href="/index.xhtml" onclick="clearBreadCrumbs()">
                    <i class="fa fa-home"></i>
                    <span>Home</span>
                </p:link>
            </li>
	        <li class="header">
	            General
	        </li>
	        <li>
	            <p:link href="/car-list.xhtml">
	                <i class="fa fa-car"></i>
	                <span>Cars</span>
	            </p:link>
	        </li>
        </ul>
     </ui:define>

    <ui:define name="top-menu">
        <ui:include src="/includes/top-bar.xhtml"/>
    </ui:define>

      <ui:define name="title">
        <h2 class="align-center">
            Welcome to the <span class="text-aqua"> <i><a href="https://github.com/adminfaces/admin-starter" target="_blank"
                                                          style="text-transform: none;text-decoration: none"> AdminFaces Starter</a></i></span> Project!
            <br/>
            <small>Integrating <p:link value="Primefaces" href="http://primefaces.org"/>, <p:link value="Bootstrap"
                                                                                                  href="http://getbootstrap.com/"/> and
                <p:link value="Admin LTE" href="https://almsaeedstudio.com/themes/AdminLTE/index2.html/"/> into your
                <p:link value="JSF" href="https://javaserverfaces.java.net/"/> application.
            </small>
        </h2>
    </ui:define>

    <ui:define name="description">
        A page description
    </ui:define>

    <ui:define name="body">
    	<h2>Page body</h2>
    </ui:define>


    <ui:define name="footer">
          <a target="_blank"
           href="https://github.com/adminfaces/">
            Copyright (C) 2017 - AdminFaces
        </a>

        <div class="pull-right hidden-xs" style="color: gray">
            <i>1.0.0</i>
        </div>
    </ui:define>


</ui:composition>
  1. /admin.xhtml is the location of the template

The above page definition renders as follows:

template example

There are also other regions defined in admin.xhtml template, see here.

2. Configuration

Template configuration is made through admin-config.properties file present in src/main/resources folder.

Here are the default values as well as its description:

admin.loginPage=login.xhtml (1)
admin.indexPage=index.xhtml (2)
admin.dateFormat=MM/dd/yyyy HH:mm:ss (3)
admin.templatePath=admin.xhtml (4)
admin.breadcrumbSize=5 (5)
admin.renderMessages=true (6)
admin.renderAjaxStatus=true (7)
admin.disableFilter=false (8)
  1. login page location (relative to webapp). It you only be used if you configure Admin Session.

  2. index page location. User will be redirected to it when it access app root (contextPath/).

  3. Date format used in error page (500.xhtml).

  4. facelets template to be used on build in admin-template pages like 500.xhtml, 404.xhtml, viewexpired.xhtml. By default it uses admin.xhtml but you can define any template (e.g one that extends admin.xhtml).

  5. Number of breadcrumbs to queue before removing the older ones.

  6. When false, p:messages defined in admin template will not be rendered.

  7. When false ajaxStatus, which triggers the loading bar on every ajax request, will not be rendered.

  8. Disables AdminFilter, responsible for redirecting user after session timeout, sending user to logon page when it is not logged in among other things.

You don’t need to declare all values in your admin-config.properties, you can specify only the ones you need in order to change.

3. Admin Session

AdminSession is a simple session scoped bean which controls whether user is logged in or not.

 public boolean isLoggedIn(){
        return isLoggedIn; //always true by default
    }

By default the user is always logged in and you need to override it (by using bean specialization or calling setIsLoggedIn() method) to change its value.

When isLoggedIn is false you got the following mechanisms activated:

  1. Access to any page, besides the login, redirects user to login;

  2. When session is expired user is redirected to logon and current page (before expiration) is saved so user is redirected back to where it was before session expiration.

ℹ️
It is up to you to decide whether the user is logged in or not.

About

JSF admin template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 60.8%
  • HTML 28.3%
  • JavaScript 10.9%