// Get client id and init message + key
String clientId = component.getClientId();
FacesMessage facesMessage = null;
- String requiredMessage;
+ String requiredMessage = null;
// So far all fine, no check if the field is fine
for (final String field : requiredFields) {
// Is it the same?
if (clientId.endsWith(field)) {
- // Compare value's type
- if ((!allowNull) && (!(value instanceof Long))) {
- // Generate message
- requiredMessage = MessageFormat.format("Field {0} is not Long.: {1}", field, value); //NOI18N
-
- // Value is not right type
- facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
- break;
- } else if ((!allowNull) && (!(value instanceof Integer))) {
- // Generate message
- requiredMessage = MessageFormat.format("Field {0} is not Integer.: {1}", field, value); //NOI18N
-
- // Value is not right type
- facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage); //NOI18N
- break;
- }
-
- // Declare variables
+ // Init variables
Integer i = null;
Long l = null;
- // Which type?
- if (value instanceof Integer) {
- // Cast to Long
+ // Compare value's type
+ if (value instanceof String) {
+ // Is a string, try long
+ try {
+ l = Long.valueOf((String) value);
+ } catch (final NumberFormatException ex) {
+ // Cannot parse string to long
+ requiredMessage = MessageFormat.format("Field {0} cannot be parsed to long: {1}, exception:{2}", field, value, ex);
+
+ // Abort processing here
+ break;
+ }
+ } else if (value instanceof Integer) {
+ // Is integer
i = (Integer) value;
- } else {
- // Cast to Long
+ } else if (value instanceof Long) {
+ // Is long
l = (Long) value;
}
requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", i, field); //NOI18N
// Abort processing here
- facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
break;
} else if ((!allowNull) && ((l instanceof Long) && (l < 0))) {
// Generate message
requiredMessage = MessageFormat.format("Value {0} for field {1} is below zero.", l, field); //NOI18N
// Abort processing here
- facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
break;
}
}
}
+ // Is requiredMessage set?
+ if (null != requiredMessage) {
+ // Embed into FacesMessage
+ facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage);
+ }
+
// Is facesMessage set?
if (null != facesMessage) {
// Abort here