added validationFailed support

This commit is contained in:
2020-02-26 23:08:16 +01:00
parent 9090b2c66e
commit e12127f6dd

View File

@ -31,22 +31,18 @@ public abstract class FacesUtil {
} }
/** /**
* returns true, if the current request is in the request phase. False * returns true, if the current request is in the request phase. False otherwise.
* otherwise.
* *
* @return true, if the current request is in the request phase. False * @return true, if the current request is in the request phase. False otherwise.
* otherwise.
*/ */
public static boolean isRenderRequest() { public static boolean isRenderRequest() {
return !FacesContext.getCurrentInstance().getRenderResponse(); return !FacesContext.getCurrentInstance().getRenderResponse();
} }
/** /**
* returns true, if the current request is in the response phase. True * returns true, if the current request is in the response phase. True otherwise.
* otherwise.
* *
* @return true, if the current request is in the response phase. True * @return true, if the current request is in the response phase. True otherwise.
* otherwise.
*/ */
public static boolean isRenderResponse() { public static boolean isRenderResponse() {
return FacesContext.getCurrentInstance().getRenderResponse(); return FacesContext.getCurrentInstance().getRenderResponse();
@ -56,8 +52,7 @@ public abstract class FacesUtil {
* Adds the given message to the "messages" object * Adds the given message to the "messages" object
* *
* @param message the message to display * @param message the message to display
* @deprecated use addMessage(clientId, message) or * @deprecated use addMessage(clientId, message) or addGlobalMessage(message) instead
* addGlobalMessage(message) instead
*/ */
@Deprecated @Deprecated
public static void addMessage(FacesMessage message) { public static void addMessage(FacesMessage message) {
@ -142,8 +137,22 @@ public abstract class FacesUtil {
* @param detail the detailed message to display * @param detail the detailed message to display
*/ */
public static void addGlobalErrorMessage(String summary, String detail) { public static void addGlobalErrorMessage(String summary, String detail) {
addGlobalErrorMessage(summary, detail, false);
}
/**
* Adds the given message as global message with severity "Error".
*
* @param summary the summary message to display
* @param detail the detailed message to display
* @param valiationFailed if set to true, the method calls currentInstance().validationFailed() to invalidate the current request.
*/
public static void addGlobalErrorMessage(String summary, String detail, boolean valiationFailed) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail);
FacesContext.getCurrentInstance().addMessage(null, message); FacesContext.getCurrentInstance().addMessage(null, message);
if (valiationFailed) {
FacesContext.getCurrentInstance().validationFailed();
}
} }
/** /**
@ -168,12 +177,10 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "messages" and severity * Adds the given message to the object with id "messages" and severity "Information".
* "Information".
* *
* @param summary the message to display * @param summary the message to display
* @deprecated use addInfoMessage(clientId, summary) or addGlobalInfoMessage * @deprecated use addInfoMessage(clientId, summary) or addGlobalInfoMessage instead
* instead
*/ */
@Deprecated @Deprecated
public static void addInfoMessage(String summary) { public static void addInfoMessage(String summary) {
@ -181,13 +188,11 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "messages" and severity * Adds the given message to the object with id "messages" and severity "Information".
* "Information".
* *
* @param summary the summary message to display * @param summary the summary message to display
* @param detail the detailed message to display * @param detail the detailed message to display
* @deprecated use addInfoMessage (clientId, summary, detail) or * @deprecated use addInfoMessage (clientId, summary, detail) or addGlobalInfoMessage(summary, detail) instead
* addGlobalInfoMessage(summary, detail) instead
*/ */
@Deprecated @Deprecated
public static void addInfoMessage(String summary, String detail) { public static void addInfoMessage(String summary, String detail) {
@ -195,8 +200,7 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message with severity "Info" to the object with the id * Adds the given message with severity "Info" to the object with the id specified by clientId.
* specified by clientId.
* *
* @param clientId the id of the object to bind the message to. * @param clientId the id of the object to bind the message to.
* @param summary the summary message to display * @param summary the summary message to display
@ -208,12 +212,10 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "warnings" and severity * Adds the given message to the object with id "warnings" and severity "Error".
* "Error".
* *
* @param summary the message to display * @param summary the message to display
* @deprecated use addErrorMessage (clientId, summary, detail) or * @deprecated use addErrorMessage (clientId, summary, detail) or addGlobalErrorMessage(summary, detail) instead
* addGlobalErrorMessage(summary, detail) instead
*/ */
@Deprecated @Deprecated
public static void addErrorMessage(String summary) { public static void addErrorMessage(String summary) {
@ -221,14 +223,12 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "warnings" and severity * Adds the given message to the object with id "warnings" and severity "Error".
* "Error".
* *
* *
* @param summary the summary message to display * @param summary the summary message to display
* @param detail the detailed message to display * @param detail the detailed message to display
* @deprecated use addErrorMessage (clientId, summary, detail) or * @deprecated use addErrorMessage (clientId, summary, detail) or addGlobalErrorMessage(summary, detail) instead
* addGlobalErrorMessage(summary, detail) instead
*/ */
@Deprecated @Deprecated
public static void addErrorMessage(String summary, String detail) { public static void addErrorMessage(String summary, String detail) {
@ -236,8 +236,7 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message with severity "Error" to the object with the id * Adds the given message with severity "Error" to the object with the id specified by clientId.
* specified by clientId.
* *
* @param clientId the id of the object to bind the message to. * @param clientId the id of the object to bind the message to.
* @param summary the summary message to display * @param summary the summary message to display
@ -249,12 +248,10 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "warnings" and severity * Adds the given message to the object with id "warnings" and severity "Warning".
* "Warning".
* *
* @param summary the message to display * @param summary the message to display
* @deprecated use addWarningMessage (clientId, summary, detail) or * @deprecated use addWarningMessage (clientId, summary, detail) or addGlobalWarningMessage(summary, detail) instead
* addGlobalWarningMessage(summary, detail) instead
*/ */
@Deprecated @Deprecated
public static void addWarningMessage(String summary) { public static void addWarningMessage(String summary) {
@ -262,13 +259,11 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "warnings" and severity * Adds the given message to the object with id "warnings" and severity "Warning".
* "Warning".
* *
* @param summary the summary message to display * @param summary the summary message to display
* @param detail the detailed message to display * @param detail the detailed message to display
* @deprecated use addWarningMessage (clientId, summary, detail) or * @deprecated use addWarningMessage (clientId, summary, detail) or addGlobalWarningMessage(summary, detail) instead
* addGlobalWarningMessage(summary, detail) instead
*/ */
@Deprecated @Deprecated
public static void addWarningMessage(String summary, String detail) { public static void addWarningMessage(String summary, String detail) {
@ -277,8 +272,7 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message with severity "Warning" to the object with the id * Adds the given message with severity "Warning" to the object with the id specified by clientId.
* specified by clientId.
* *
* @param clientId the id of the object to bind the message to. * @param clientId the id of the object to bind the message to.
* @param summary the summary message to display * @param summary the summary message to display
@ -290,13 +284,11 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message to the object with id "warnings" and severity * Adds the given message to the object with id "warnings" and severity "Fatal".
* "Fatal".
* *
* @param summary the summary message to display * @param summary the summary message to display
* @param detail the detailed message to display * @param detail the detailed message to display
* @deprecated use addFatalMessage (clientId, summary, detail) or * @deprecated use addFatalMessage (clientId, summary, detail) or addGlobalFatalMessage(summary, detail) instead
* addGlobalFatalMessage(summary, detail) instead
*/ */
@Deprecated @Deprecated
public static void addFatalMessage(String summary, String detail) { public static void addFatalMessage(String summary, String detail) {
@ -305,8 +297,7 @@ public abstract class FacesUtil {
} }
/** /**
* Adds the given message with severity "Fatal" to the object with the id * Adds the given message with severity "Fatal" to the object with the id specified by clientId.
* specified by clientId.
* *
* @param clientId the id of the object to bind the message to. * @param clientId the id of the object to bind the message to.
* @param summary the summary message to display * @param summary the summary message to display