raimund@1504: package de.intevation.flys.client.client.utils; raimund@1504: raimund@1504: import java.util.Map; raimund@1504: raimund@1507: import com.google.gwt.core.client.GWT; raimund@1507: raimund@1504: import com.smartgwt.client.widgets.form.fields.FormItem; raimund@1504: raimund@1507: import de.intevation.flys.client.client.FLYSConstants; raimund@1507: raimund@1504: /** raimund@1504: * @author Raimund Renkert raimund@1504: */ raimund@1507: public class IntegerValidator implements Validator { raimund@1507: raimund@1507: /** The interface that provides i18n messages. */ raimund@1507: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); raimund@1504: raimund@1504: /** raimund@1504: * raimund@1504: */ raimund@1507: public boolean validate(FormItem item, Map errors) { raimund@1504: boolean valid = true; raimund@1504: raimund@1507: String v = item.getValue().toString(); raimund@1504: raimund@1504: try { raimund@1504: if (v == null) { raimund@1504: throw new NumberFormatException("empty"); raimund@1504: } raimund@1504: raimund@1504: int value = Integer.parseInt(v); raimund@1504: raimund@1504: errors.remove(item.getFieldName()); raimund@1504: } raimund@1504: catch (NumberFormatException nfe) { raimund@1504: errors.put(item.getFieldName(), MSG.wrongFormat()); raimund@1504: raimund@1504: item.focusInItem(); raimund@1504: raimund@1504: valid = false; raimund@1504: } raimund@1504: return valid; raimund@1504: } raimund@1504: }