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