JSF notifications (quick dirty tutorial)


Just simple idea, to use javascript api to jsf ajax events to show notifications from server on page after request or ajax.


and then use it for display notification on website.

First create bean class for storing messages

public class Notifi {
  public String msg;
  public String getMsg() {
    String tmp = msg;
    msg = ""; // reset msg
    return tmp;}

Next implement notifi javascript method

function notifi() {
jQuery.get(‘#{request.contextPath}’ + "/notifi.jsp", {}, function (data) {console.log(data)};

Then in main folder create file notifi.jsp, it will be page that will shows messages for ajax requests

<%@page contentType="text/html" pageEncoding="UTF-8"%>${widokKosci.powiadomienia.wiadomosc}

Last one, use notifi bean after first page render, for non ajax requests, for example at the bottom of template file


Finally just use Notifi bean

Notifi notifi;

public void action() {
notifi.msg = "Hello!";


You could add extra data for notifications, exceptions etc.

You could use other method to show messages, rather than use “console.log” eg. pnotiffi

You could add stack for messages and other ways to manage messages.

Happy coding!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s