【问题标题】:Displaying an error message from a4j:jsFunction显示来自 a4j:jsFunction 的错误消息
【发布时间】:2013-05-16 23:16:53
【问题描述】:

我在下面有这个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.

【问题讨论】:

    标签: jsf richfaces


    【解决方案1】:

    使用a4j:jsFunction,您只是在执行 Ajax 调用;视图不会刷新,其他组件将继续保持之前的状态。

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

    【讨论】:

    • 所以我用 id 扩展h:message&lt;h:messages id="messageForm" for="createEvent" style="color:red" /&gt; 并将reRender="messageForm" 添加到a4j:jsFunction。我也尝试了不同的可能性,例如reRender 包裹在 h:message 周围的元素。但我没有工作。我需要重新渲染什么?
    【解决方案2】:

    我最近遇到了类似的问题。我用的是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 方法时被调用。支持 bean 正在使用 addMessage 方法添加 FacesMessages:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 2017-10-05
      相关资源
      最近更新 更多