获取消息类型 PrimeFaces
Fetching message type PrimeFaces
我正在使用 primefaces 并提交表单。如果支持 bean 中发生任何异常,则会抛出一条错误消息。我需要使用 javascript 执行一些操作,以防出现错误消息。
目前我正在使用以下代码,但我得到的 facesContext.maximumSeverity 为空。
<p:commandButton action="#{backingBean.fetchSearchResults()}"
update="@form :searchResults" value="Update"
actionListener="#{backingBean.updateDetails()}" validateClient="true"
oncomplete="handleResponse(xhr, status, args)" />
<h:outputScript target="head">
function handleResponse(xhr, status, args) {
if( args.notValid || args.validationFailed) {
alert('Balls 1');
return;
} else if (#{facesContext.maximumSeverity==null or facesContext.maximumSeverity.compareTo(FacesMessage.SEVERITY_ERROR) ge 0}) {
alert('Balls 2');
return;
} else if (#{facesContext.maximumSeverity==null or facesContext.maximumSeverity.ordinal=='1'}) {
alert('Balls 3');
return;
} else {
alert('Everything is Ok.');
}
}
</h:outputScript>
您错误地假设 #{facesContext.maximumSeverity==null or facesContext.maximumSeverity.ordinal=='1'}
在 javascript 被调用时被求值。它不是。它在页面呈现时进行评估。那时,严重性的值很可能为空。
我正在使用 primefaces 并提交表单。如果支持 bean 中发生任何异常,则会抛出一条错误消息。我需要使用 javascript 执行一些操作,以防出现错误消息。 目前我正在使用以下代码,但我得到的 facesContext.maximumSeverity 为空。
<p:commandButton action="#{backingBean.fetchSearchResults()}"
update="@form :searchResults" value="Update"
actionListener="#{backingBean.updateDetails()}" validateClient="true"
oncomplete="handleResponse(xhr, status, args)" />
<h:outputScript target="head">
function handleResponse(xhr, status, args) {
if( args.notValid || args.validationFailed) {
alert('Balls 1');
return;
} else if (#{facesContext.maximumSeverity==null or facesContext.maximumSeverity.compareTo(FacesMessage.SEVERITY_ERROR) ge 0}) {
alert('Balls 2');
return;
} else if (#{facesContext.maximumSeverity==null or facesContext.maximumSeverity.ordinal=='1'}) {
alert('Balls 3');
return;
} else {
alert('Everything is Ok.');
}
}
</h:outputScript>
您错误地假设 #{facesContext.maximumSeverity==null or facesContext.maximumSeverity.ordinal=='1'}
在 javascript 被调用时被求值。它不是。它在页面呈现时进行评估。那时,严重性的值很可能为空。