해결책은 간단합니다. 메시지를 AlfrescoRuntimeException
에게 보내십시오.
throw new AlfrescoRuntimeException("your.message");
그런 경우 메시지가 표시되지만 느슨한 예외 하위 유형이 있습니다.
은 야외 자바 스크립트 코드에서 예외 처리를봤을 때 내가 놀랐어 어떻게 말로 설명하기가 정말 어렵습니다 :
onFormSubmitFailure: function FormManager_onFormSubmitFailure(response)
{
var failureMsg = null;
if (response.json && response.json.message && response.json.message.indexOf("Failed to persist field 'prop_cm_name'") !== -1)
{
failureMsg = this.msg("message.details.failure.name");
}
else if (response.json && response.json.message && response.json.message.indexOf("PropertyValueSizeIsMoreMaxLengthException") !== -1)
{
failureMsg = this.msg("message.details.failure.more.max.length");
}
else if (response.json && response.json.message && response.json.message.indexOf("org.alfresco.error.AlfrescoRuntimeException") == 0)
{
var split = response.json.message.split(/(?:org.alfresco.error.AlfrescoRuntimeException:\s*\d*\s*)/ig);
if (split && split[1])
{
failureMsg = split[1];
}
}
Alfresco.util.PopupManager.displayPrompt(
{
title: this.msg(this.options.failureMessageKey),
text: failureMsg ? failureMsg : (response.json && response.json.message ? response.json.message : this.msg("message.details.failure"))
});
},
당신이 자바에서 그들은 "캐치"클래스 이름을보고 메시지로 대체 할 수있다. 고객의 예외 사항을 처리 할 수있는보다 확장 가능한 방법을 제공하기를 바랍니다.
P. 물론 또 다른 방법은 alfresco.js
파일을 확장하고 하나 더 if else
조건을 예외로 추가하는 것입니다.
예외에서'toString()'을 호출하는 대신'getMessage()'를 사용하여 메시지를 꺼내려고 했습니까? – Gagravarr