Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9072529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:11:27+00:00 2026-06-16T18:11:27+00:00

How to make a primefaces template that includes ajax status for global use. So

  • 0

How to make a primefaces template that includes ajax status for global use.

So far this is what I’ve done.

template/default.xhtml (Facelets Template)

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="./../resources/css/default.css" rel="stylesheet" type="text/css" />
    <link href="./../resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
    <title>Facelets Template</title>
</h:head>

<h:body>

    <div id="top">
        <ui:insert name="top">
            <!--modal ajax status here-->
            <p:ajaxStatus onstart="statusDialog.show();" oncomplete="statusDialog.hide();"/>  

            <p:dialog modal="true" widgetVar="statusDialog" header="Loading"   
                      draggable="false" closable="false">  
                <p:graphicImage value="../resources/images/ajax-loader-square.gif" />  
            </p:dialog>
            <!--modal ajax status end-->
        </ui:insert>
    </div>

    <div id="content" class="center_content">
        <ui:insert name="content">Content</ui:insert>
    </div>

    <div id="bottom">
        <ui:insert name="bottom">Bottom</ui:insert>
    </div>

</h:body>

login.xhtml (Facelets Template Client)

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>

        <ui:composition template="./../../template/default.xhtml">

            <ui:define name="top">
                top
            </ui:define>

            <ui:define name="content">
                <h:form id="form1"> 

                    <p:focus context="form1"/> 

                    <table style="width: 200px; border: solid;">
                        <tbody>
                            <!--output msg here-->
                            <tr>
                                <td>
                                    <p:messages />
                                </td>
                            </tr>
                            <!--output msg end-->

                            <!--input here-->
                            <tr>
                                <td>
                                    <p:outputLabel for="txtUname" value="Username:" />
                                    <p:inputText id="txtUname" value="#{loginController.username}" size="20" required="true" requiredMessage="Username is required!" maxlength="45"/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p:outputLabel for="txtPass" value="Password:" />
                                    <p:password id="txtPass" value="#{loginController.password}" size="20" required="true" requiredMessage="Password is required!"/>
                                </td>
                            </tr>
                            <!--input end-->

                            <tr>
                                <th>
                                    <!--ajax submit-->
                                    <p:commandButton value="Login" update="form1" actionListener="#{loginController.validateAccount()}"/>
                                </th>
                            </tr>
                        </tbody>
                    </table>
                </h:form> 
            </ui:define>

            <ui:define name="bottom">
                bottom
            </ui:define>

        </ui:composition>

    </body>
</html>

LoginController.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.io.IOException;
import java.util.List;
import javax.faces.FacesException;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import util.NewHibernateUtil;

/**
 *
 * @author burhan
 */
@ManagedBean
@RequestScoped
public class LoginController {

    private String username;
    private String password;

    /**
     * Creates a new instance of LoginController
     */
    public LoginController() {
    }

    private String redirect(String targetPage) {

        FacesContext ctx = FacesContext.getCurrentInstance();

        ExternalContext extContext = ctx.getExternalContext();
        String url = extContext.encodeActionURL(ctx.getApplication().getViewHandler().getActionURL(ctx, targetPage));

        try {

            extContext.redirect(url);
        } catch (IOException ioe) {
            throw new FacesException(ioe);

        }
        return null;

    }

    public void validateAccount() {
        if (!validateAccount(username, password)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Invalid username or password!", "WARNING"));
            username = "";
            password = "";
            return;
        }

        redirect("/views/home.xhtml");

    }

    public boolean validateAccount(String username, String password) {
        Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tx = session.beginTransaction();

        Query q = session.createQuery(""
                + "SELECT COUNT(entity) "
                + "FROM "
                + "UserCatalog entity "
                + "WHERE "
                + "entity.username = :uname "
                + "AND "
                + "entity.password = MD5(:pass) "
                + "AND "
                + "entity.active = TRUE "
                + "");
        q.setParameter("uname", username);
        q.setParameter("pass", password);

        List list = q.list();

        tx.commit();

        if (Integer.parseInt(list.get(0).toString()) == 0) {
            return false;
        }

        return true;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
}

but the ajax status doesn’t seem to appear.

note: all methods are working correctly and it takes at least 2 seconds to show the target page. I can see on my google chrome browser tab the loading circle when I click the command button. but not the ajax status. It only works when I place an ajax status tag to every page (even w/o global=”true” attribute) but it kills the purpose of template and I have lots of xhtml pages w/ command buttons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:11:28+00:00Added an answer on June 16, 2026 at 6:11 pm

    Any content of <ui:insert> in the template master becomes the default content whenever the template child does not declare any <ui:define> for that. You need to put the ajax status content outside the <ui:insert> if you intend to have it on every template child, also the ones which have <ui:define> declared for top.

    <!--modal ajax status here-->
    <p:ajaxStatus onstart="statusDialog.show();" oncomplete="statusDialog.hide();"/>  
    
    <p:dialog modal="true" widgetVar="statusDialog" header="Loading"   
              draggable="false" closable="false">  
        <p:graphicImage value="../resources/images/ajax-loader-square.gif" />  
    </p:dialog>
    <!--modal ajax status end-->
    
    <ui:insert name="top">
        Some default top content.
    </ui:insert>
    

    See also:

    • How to include another XHTML in XHTML using JSF 2.0 Facelets?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i make one class file for jar. and this class have use wurfl. and
I have a inputTextarea that I refresh using PrimeFaces' AJAX poll. When the inputTextarea
I have a button in primefaces, that when is pressed I make some calculations
I'm trying to make use of the Star Rating component from PrimeFaces. However, it
I am using primefaces selectOneButton. I want to make some buttons in that selectOneButton
Make it on Linux. The reason to use more than one version of Vim,
I make an app that have to printing image. I need to print image
SOLUTION Make sure in the plist that the storyboard name is listed as the
I make my notes in this order: * FIRST * SECOND * THIRD ...
I make an ajax call to a servlet's post method from my js file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.