显示来自a4j:jsFunction的错误消息

时间:2013-05-16 23:16:54

标签: jsf richfaces

我在下方有a4j:jsFunction,在页面上的其他地方有<h:message for="form" style="color:red" />

<h:form id="form">
    <a4j:jsFunction id="createEvent" name="createEvent" immediate="true"
        action="#{calendarController.createEvent()}"
        data="#{calendarController}"
        oncomplete="renderEvent(event.data.eventId, event.data.eventTitle)">
        <a4j:param name="eventTitle"
            assignTo="#{calendarController.eventTitle}" />
    </a4j:jsFunction>
</h:form>

如何添加calendarController.createEvent()生成的错误消息?

使用context.addMessage("form", new FacesMessage(e.getMessage()));尝试但不起作用。我收到此错误:WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.

2 个答案:

答案 0 :(得分:1)

使用a4j:jsFunction,您只是在执行Ajax调用;视图未刷新,其他组件将继续处于以前的状态。

使用reRender属性强制刷新h:message组件。

答案 1 :(得分:0)

我最近遇到过类似的问题。我正在使用h:commandButton

        <h:commandButton id="buttonOK"
                         onclick = "#{rich:component('purchasePopup')}.hide(); finishPurchase();"
                         value="Ok"
                         styleClass="popupPrimary"
                         rendered="#{validationSeverity != 'ERROR'}"
                         type="button">
        </h:commandButton>

我还有jsFunction,可以在按钮点击和调用支持bean方法上调用。 Backing bean使用addMessage方法添加FacesMessages:

<a4j:jsFunction name="finishPurchase" action="finish" render="purchaseForm"/>

解决方案是添加render="purchaseForm",因为所有标记都嵌套在此表单中。