PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] Why my JSF application doesn't show the context message?

 July 12, 2022     jsf, message, redirect     No comments   

Issue

I am working with Prime Faces and I would like user start in a index page, press a button for call a function (registrarUsuario) for reload the index page and show the context message. My problem is my application doesn't show the message. This is my code:

index.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:b="http://bootsfaces.net/ui">
...
<h:form>
    <b:commandButton action = "#{registroUsuario.registrarUsuario}" value = "call function"/>
</h:form>
....

RegistroUsuario.java:

public void registrarUsuario() throws IOException, Exception {
    try {
        //another code
        FacesMessage message = new FacesMessage(":D", "message");
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, message);
    } catch (Exception e) {
        FacesMessage message = new FacesMessage("Falla", e.toString());
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, message);
    }finally{
        FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
    }

}

Thank you!


Solution

This happens because Primefaces does not preserve Messages through a redirect.

One possibility to cope with this is to add a filter which passes all unrendered messages to after the redirect. This answer provides a solution: Show success message and then redirect to another page after a timeout using PageFlow



Answered By - Abaddon666
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing