01: package com.sun.portal.admin.console.sra.validators;
02:
03: import java.awt.geom.Arc2D.Double;
04: import java.io.Serializable;
05:
06: import javax.faces.application.FacesMessage;
07: import javax.faces.component.UIComponent;
08: import javax.faces.context.FacesContext;
09: import javax.faces.validator.Validator;
10: import javax.faces.validator.ValidatorException;
11:
12: import com.sun.portal.admin.console.sra.ISraBean;
13: import com.sun.portal.admin.console.sra.utils.Util;
14:
15: public class NumericValueValidator implements Serializable, Validator {
16: public void validate(FacesContext context, UIComponent component,
17: Object val) throws ValidatorException {
18: String value = "";
19:
20: if (val instanceof String) {
21: value = (String) val;
22: try {
23: Integer.parseInt(value);
24: } catch (NumberFormatException nfe) {
25: notANumberExceptionMessage();
26: }
27: }
28: }
29:
30: private void notANumberExceptionMessage() {
31: FacesMessage message = new FacesMessage();
32: String err_message = Util.getLocalizedMessageForKey(
33: ISraBean.RB_NAME, "not.number.error");
34:
35: message.setDetail(err_message);
36: message.setSummary(err_message);
37: message.setSeverity(FacesMessage.SEVERITY_ERROR);
38: throw new ValidatorException(message);
39: }
40: }
|