PrimeFaces AutoUpdate

In one of our PrimeFaces powered applications, we use a single growl component placed in a template of the application. All application wide messages are displayed using this growl so each page using the template does not need to define it every time. Problem is on every page we need to update this growl component for most of the ajax requests like commandButton update=”growl”, commandLink update=”growl”, instead I’ve thought of a way to auto update it on every ajax request. Growl is a lightweight component with small output size, it just renders strings and on client side those strings are used to generate actual dom elements so there is not much effect in terms of performance if we update it every time.

So I’ve added autoUpdate option to growl, messages and outputPanel component, now if you find yourself constantly updating the same component like messages, setting autoUpdate will make things easier. Consider the following example;

<h:form>
    <p:messages id="msgs" showDetail="true" />
				
    <p:commandButton value="Info" actionListener="#{messagesController.addInfo}" update="msgs"/>
    <p:commandButton value="Warn" actionListener="#{messagesController.addWarn}" update="msgs"/>
    <p:commandButton value="Error" actionListener="#{messagesController.addError}" update="msgs"/>
    <p:commandButton value="Fatal" actionListener="#{messagesController.addFatal}" update="msgs"/>
</h:form>

becomes;

<h:form>
    <p:messages showDetail="true" autoUpdate="true"/>
				
    <p:commandButton value="Info" actionListener="#{messagesController.addInfo}"/>
    <p:commandButton value="Warn" actionListener="#{messagesController.addWarn}"/>
    <p:commandButton value="Error" actionListener="#{messagesController.addError}"/>
    <p:commandButton value="Fatal" actionListener="#{messagesController.addFatal}"/>
</h:form>

In our app, now I can set enabled autoUpdate of central growl component in page and forget updating it in every page.

This handy feature will be in PrimeFaces 3.0 starting with M1.

10 Responses to PrimeFaces AutoUpdate

  1. Anton says:

    Very-very-very useful! This is one of few features, which lacked in PF, comparing with other UI frameworks. Thanks, Cagatay!

  2. Oleg says:

    Hello Cagatay,

    I’m glad to see this feature in PrimeFaces. I was waiting for this features a long time because RichFaces always had it. So now we have it in PrimeFaces. Very well.

    I have implemented a similar feature in my web app by means of an extended PartialViewContextWrapper. The method
    public Collection getExecuteIds()
    has to be overwritten in order to add additional IDs. The same concept is valid for getRenderIds() how shown in this post http://insights2jsf.wordpress.com/2010/10/17/wrapping-partialviewcontext-or-howto-automatically-add-clientids-to-render-on-ajax-requests/

    Many thanks.

  3. Glad to hear that you guys also think this feature would be useful.

  4. Oleg says:

    What would be useful yet – two new parameters like

    That’s for the case if you have both growl and messages on a page and want to show one or another, but not both. I have solved this lack by means of “render” attribute (value come from backing bean) defined for both components. The control of this behavior with only one attribute (either growl or message(s)) would be nice to have.

  5. Ulisses says:

    Great feature!
    Very useful.

  6. Oleg says:

    Code was truncated. I meant this code

    <p:growl growlOnly="true" …/>
    <p:messages messagesOnly="true" …/>

  7. mpashworth says:

    This is a very handy feature🙂

  8. Nei Alcantara Jr. says:

    This feature was excellent, I have a lot of updating pages and does not need to pass the id in all the updates much quicker.

    Thanks Cagatay !

  9. JĂ©rĂ´me Jadoulle says:

    This is a very much welcomed addition to the framework.
    Although it seems tiny, it helps a lot when dealing with error messages happening potentially anywhere in the app.

    One pain less to solve “by hand”.
    Thank you very much for your hard work! It is very appreciated!

  10. Hi Cagatay,

    my understanding is that autoUpdate works in conjunction with an action or actionListener.
    Is there a way to update/autoUpdate growl when a FacesMessage was added to the FacesContext inside a managedBean constructor or @PostConstruct method?

    Thanks.
    Stephan

%d bloggers like this: