How to use Primefaces' p:growl and redirect to a page

后端 未结 3 868
忘了有多久
忘了有多久 2020-12-06 10:21

hi im kind of new at jsf enviroment, im trying to update a primefaces growl and then redirect to a page from a commandButton action.

 

        
相关标签:
3条回答
  • 2020-12-06 11:01

    Add another growl to page you redirect

    like this <p:growl id="growlmsg2" showDetail="true" sticky="true" autoUpdate="true"/>

    0 讨论(0)
  • 2020-12-06 11:16

    Messages get lost during redirect. You can use the flash to keep messages.

    Add the following before returning from your action method:

    FacesContext context = FacesContext.getCurrentInstance();
    context.getExternalContext().getFlash().setKeepMessages(true);
    
    0 讨论(0)
  • 2020-12-06 11:26

    Because Flash has bug, my solution is to make a separated redirect button which will be hit after showing msg:

    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.
    }
    
    0 讨论(0)
提交回复
热议问题