0

I have a JSF page with Primefaces growl. I want to make visible message when I switch between pages. Is this possible?

user1285928
  • 1,328
  • 29
  • 98
  • 147

2 Answers2

2

In the @PostConstruct method (or the constructor) of the second page's bean, add a FacesMessage, e.g.:

context.addMessage(null, new FacesMessage("Growl Message", "Growl Message Text"));  
BestPractices
  • 12,738
  • 29
  • 96
  • 140
  • 1
    Note that the bean must be `@ViewScoped`. – BalusC Jul 18 '12 at 03:48
  • I forgot to mention about one detail: I have a JSF page `Accounts` where I can see a list of a users and I also have JSF page with form for adding users. I want when I add new user to redirect the user to page `Accounts` and display Primefaces growl message "Success". In this example every time when I refresh page `Accounts` I will see the message. How I can solve this problem? – user1285928 Jul 18 '12 at 12:32
  • try adding redisplay="false" to your growl component definition e.g. – BestPractices Jul 18 '12 at 15:55
  • If this answer worked for you, please remember to mark it as approved using the check mark to the left of the answer. Thanks. – BestPractices Jul 19 '12 at 13:14
0

Here is my solution. It will show the msg in the current page before redirect.

HTML:

<h:form prependId="false">
    <p:growl />
    <p:button outcome="gotoABC" id="rdr-btn" style="display: none;" />
    <p:commandButton action="#{bean.process()}" update="@form" />
</form>

Bean:

public void process(){
    addInfoMsg(summary, msgDetail); //Add msg func
    RequestContext.getCurrentInstance().execute("setTimeout(function(){ $('#rdr-btn').click(); }, 3000);"); // 3 seconds delay. I put the script in Constants to config later.
}
Quân Trần
  • 31
  • 1
  • 6