问题描述
我们正在使用以下代码在验证文档时添加新的错误消息:
We are using the following code for adding new error messages while validating the document:
function addFacesMessage( message, component ){
try {
if( typeof component === 'string' ){
component = getComponent( component );
}
var clientId = null;
if( component ){
clientId = component.getClientId( facesContext );
}
facesContext.addMessage( clientId, new javax.faces.application.FacesMessage( message ) );
} catch(e){
globalScriptErrors.add(e);
requestScope.put("scriptErrors", globalScriptErrors);
}
}
我们在每个验证例程中调用此函数,如果发生错误:
We call this function in every validation routine, if an error occured:
facesContext.addMessage("",
new javax.faces.application.FacesMessage("errormessage" );
在我们的XPage中,我们有一个错误消息框显示发生的所有错误对于当前页面:
In our XPage we've got an error message box to show all errors, that have occured for the current page:
<xp:messages id="messages2" styleClass="lotusMessage lotusWarning"></xp:messages>
现在,消息显示在错误消息框中,但是如何检查这个页面有错误吗?我们想使用这个信息,例如弹出窗口,只能在错误消息框中显示错误信息,但是如何才能显示这个信息?
Now, messages are displayed in the error message box, but how can we check if there are errors for this page? We want to use this information e.g. for an popup, that only has to be displayed, if no errors are displayed in the error message box. But how do we get this information?
推荐答案
它应该适用于:
if (facesContext.getMessages().hasNext())
这里有一个工作示例:
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:if (facesContext.getMessages().hasNext())
return "there is a error message";
else
return "no message";}]]></xp:this.value>
</xp:text>
<xp:button value="no title" id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
var message = "test";
var component = "none"
try {
if( typeof component === 'string' ){
component = getComponent( component );
}
var clientId = null;
if( component ){
clientId = component.getClientId( facesContext );
}
facesContext.addMessage( clientId, new javax.faces.application.FacesMessage( message ) );
} catch(e){
globalScriptErrors.add(e);
requestScope.put("scriptErrors", globalScriptErrors);
}
}]]></xp:this.action>
</xp:eventHandler>
这篇关于获取错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!