InputNumberSpinner min max validation (UIRangedNumberInput) correction
varjupe Feb 12, 2010 4:49 AMHello,
I'm a beginner of RichFaces user. I would like to try localize an application which is using RichFaces 3.3.2.SR1.
The InputNumberSpinner component has minValue and maxValue attribute.
When the user gives a wrong value the message will be english, and there is not possible to localize this message.
I downloaded the source codes and I made some little corrections.
Please, somebody (who has access) update these parts in SVN.
The validation is in the org.richfaces.component.UIRangedNumberInput class.
The validation is in the org.richfaces.component.UIRangedNumberInput class.
I inserted some constants:
... private static final String MSG_MAXMIN_IS_NULL = "org.richfaces.component.UIRangedNumberInput.MaxMinIsNull"; private static final String MSG_VALUE_IS_NULL = "org.richfaces.component.UIRangedNumberInput.ValueIsNull"; private static final String MSG_LT_MINIMAL = "org.richfaces.component.UIRangedNumberInput.LessThatMinimal"; private static final String MSG_GT_MAXIMAL = "org.richfaces.component.UIRangedNumberInput.GreaterThanMaximal"; ...
and I replaced some line from this part:
if (value != null) { if (null == minValue || null == maxValue) { setValid(false); FacesMessage mess = new FacesMessage(label + ": conversation error, maxValue or minValue is null!"); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); } else if (minValue.doubleValue() > value.doubleValue()) { setValid(false); FacesMessage mess = new FacesMessage(label + ": input value is less than minimal value!"); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); } else if (maxValue.doubleValue() < value.doubleValue()) { setValid(false); FacesMessage mess = new FacesMessage(label + ": input value is more than maximum value!"); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); } } else { setValid(false); FacesMessage mess = new FacesMessage(label + ": input value can't be null!"); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); }
to this:
if (value != null) { if (null == minValue || null == maxValue) { setValid(false); FacesMessage mess = ComponentMessageUtil.getMessage(context, (MSG_MAXMIN_IS_NULL), new Object[] { label }); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); } else if (minValue.doubleValue() > value.doubleValue()) { setValid(false); FacesMessage mess = ComponentMessageUtil.getMessage(context, (MSG_LT_MINIMAL), new Object[] { label }); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); } else if (maxValue.doubleValue() < value.doubleValue()) { setValid(false); FacesMessage mess = ComponentMessageUtil.getMessage(context, (MSG_GT_MAXIMAL), new Object[] { label }); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); } } else { setValid(false); FacesMessage mess = ComponentMessageUtil.getMessage(context, (MSG_VALUE_IS_NULL), new Object[] { label }); mess.setSeverity(FacesMessage.SEVERITY_ERROR); context.addMessage(this.getClientId(context), mess); }
And I added some new lines to /richfaces-impl/src/main/resources/org/richfaces/component/messages.properties file:
org.richfaces.component.UIRangedNumberInput.MaxMinIsNull={0}: conversation error, maxValue or minValue is null! org.richfaces.component.UIRangedNumberInput.ValueIsNull={0}: input value can't be null! org.richfaces.component.UIRangedNumberInput.LessThatMinimal={0}: input value is less than minimal value! org.richfaces.component.UIRangedNumberInput.GreaterThanMaximal={0}: input value is more than maximum value!
And thats all. The standard localization procedures will be working after this modification.
BR,
Peter