在 <p:commandButton async="true"> 触发的方法中创建时不会显示 Growl 消息
Growl message does not show up when created in method triggered by <p:commandButton async="true">
我目前正在创建一个带有 spring 启动和 primefaces 的小型应用程序,但遇到问题,如果出现问题,我无法在我的网站上创建错误消息。
这里是 xhtml 的一些代码:
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
...
<p:commandButton id="btnStartManualCopy" styleClass="pollUpdate" async="true" value="Start" disabled="#{daqScriptController.isProcessing()}" action="#{daqScriptController.startManualCopy}" />
</h:form>
请注意,async 为真,因此在调用的方法 'startManualCopy' 正在处理时页面不会阻塞。
在方法内部 'startManualCopy' 如果在处理过程中有任何错误,我也会处理错误,并希望在页面上显示指定的消息 - 在咆哮中。
到目前为止我尝试了什么:
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error:", "Some cool text); FacesContext.getCurrentInstance().addMessage(null, msg);
或:
PrimeFacesContext.getCurrentInstance().addMessage(null, msg);
PrimeFaces.current().ajax().update(":msgs");
或:
final RequestContext context = RequestContext.getCurrentInstance();
context.update(":msgs");
注意:我为 id 尝试了一些其他组合,如 :form:msgs 等等 - 所以我可以确定地址是正确的组件。但在网络观察者中,响应从未真正在内部进行更新。
我在调试时发现,异步调用方法内的 facescontext 中的 responewriter 为 null。我添加了一个侦听器,它在 tabclose 事件的咆哮中添加了一条消息,这工作得很好。
public void onTabClose(TabCloseEvent event) {
FacesMessage msg = new FacesMessage("Tab Closed", "Closed tab: " + event.getTab().getTitle());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
知道如何显示我的用例中的错误消息吗?
谢谢
您的 commandButton 需要 update="msgs"
以告诉它在 AJAX return.
之后更新 msgs 组件
<p:commandButton async="true"
value="Start"
action="#{daqScriptController.startManualCopy}"
update="msgs" />
我目前正在创建一个带有 spring 启动和 primefaces 的小型应用程序,但遇到问题,如果出现问题,我无法在我的网站上创建错误消息。 这里是 xhtml 的一些代码:
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
...
<p:commandButton id="btnStartManualCopy" styleClass="pollUpdate" async="true" value="Start" disabled="#{daqScriptController.isProcessing()}" action="#{daqScriptController.startManualCopy}" />
</h:form>
请注意,async 为真,因此在调用的方法 'startManualCopy' 正在处理时页面不会阻塞。
在方法内部 'startManualCopy' 如果在处理过程中有任何错误,我也会处理错误,并希望在页面上显示指定的消息 - 在咆哮中。
到目前为止我尝试了什么:
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error:", "Some cool text); FacesContext.getCurrentInstance().addMessage(null, msg);
或:
PrimeFacesContext.getCurrentInstance().addMessage(null, msg);
PrimeFaces.current().ajax().update(":msgs");
或:
final RequestContext context = RequestContext.getCurrentInstance();
context.update(":msgs");
注意:我为 id 尝试了一些其他组合,如 :form:msgs 等等 - 所以我可以确定地址是正确的组件。但在网络观察者中,响应从未真正在内部进行更新。
我在调试时发现,异步调用方法内的 facescontext 中的 responewriter 为 null。我添加了一个侦听器,它在 tabclose 事件的咆哮中添加了一条消息,这工作得很好。
public void onTabClose(TabCloseEvent event) {
FacesMessage msg = new FacesMessage("Tab Closed", "Closed tab: " + event.getTab().getTitle());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
知道如何显示我的用例中的错误消息吗?
谢谢
您的 commandButton 需要 update="msgs"
以告诉它在 AJAX return.
<p:commandButton async="true"
value="Start"
action="#{daqScriptController.startManualCopy}"
update="msgs" />