Search code examples
ajaxjsfmessage

JSF update component on every ajax request


Hi i want to render the JSF messages as bootstrap alerts

<ui:repeat value="#{facesContext.messageList}" var="facesMessage">
    <div class="alert">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <strong>Warning!</strong> #{facesMessage.summary}
    </div>
</ui:repeat>

in primefaces there is

<p:messages autoUpdate=true>

means it is rerendered on every ajax request without explicit adding it to the render-attribute of a commandLink

is there a way to achieve this with plain JSF-ajax tags?


Solution

  • You might try something like this during your page load:

    jsf.ajax.addOnEvent(autoRender);
    

    And in autoRender you would be able to trigger a kind of action in order to render the target component. For instance:

    function autoRender() {
        $(":form:autoRenderHiddenButton").click();
    }
    

    And in the button:

    <h:commandButton id="autoRenderHiddenButton" 
                     style="display: none">
    
        <f:ajax render="theComponentIdYouWantToRender"/>
    </h:commandButton>
    

    Or you can easily achieve the same behavior by using Omniface's commandScript:

    <o:commandScript name="autoRender" render="theComponentIdYouWantToRender"/>