*/
private static final long serialVersionUID = 50_837_597_127_567_140L;
+ /**
+ * Returns given property key or throws an exception if not found.
+ * <p>
+ * @param parameterKey Property key
+ * <p>
+ * @return Property value
+ * <p>
+ * @throws NullPointerException If given key is not found
+ * @throws NumberFormatException If no number is given in context parameter
+ */
+ protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException {
+ // Get context parameter
+ Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey));
+
+ // Return it
+ return contextValue;
+ }
+
+ /**
+ * Returns given property key or throws an exception if not found.
+ * <p>
+ * @param parameterKey Property key
+ * <p>
+ * @return Property value
+ * <p>
+ * @throws NullPointerException If given key is not found
+ */
+ protected String getStringContextParameter (final String parameterKey) throws NullPointerException {
+ // Get context parameter
+ String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey);
+
+ // Is it null?
+ if (null == contextValue) {
+ // Throw NPE
+ throw new NullPointerException("parameterKey=" + parameterKey + " is not set.");
+ }
+
+ // Return it
+ return contextValue;
+ }
+
/**
* Checks whether debug mode is enabled for given controller
* <p>
* exception is being inserted into the message.
* <p>
* @param clientId Client id to send message to
- * @param cause Causing exception
+ * @param cause Causing exception
*/
protected void showFacesMessage (final String clientId, final Throwable cause) {
// Trace message
System.out.println(MessageFormat.format("showFacesMessage: clientId={0},cause={1} - CALLED!", clientId, cause));
// Get context and add message
- FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(cause.getMessage()));
+ this.showFacesMessage(clientId, cause.getMessage());
+ }
+
+ /**
+ * Shows a faces message with given message.
+ * <p>
+ * @param clientId Client id to send message to
+ * @param message Causing exception
+ */
+ protected void showFacesMessage (final String clientId, final String message) {
+ // Get context and add message
+ FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message));
}
}