1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.webui.validator;
18
19 import org.exoplatform.web.application.ApplicationMessage;
20 import org.exoplatform.webui.core.UIComponent;
21 import org.exoplatform.webui.exception.MessageException;
22 import org.exoplatform.webui.form.UIForm;
23 import org.exoplatform.webui.form.UIFormInput;
24 import org.exoplatform.webui.form.validator.Validator;
25
26
27
28
29
30
31
32 public class ZeroNumberValidator implements Validator {
33
34 @SuppressWarnings("unchecked")
35 public void validate(UIFormInput uiInput) throws Exception {
36 if (uiInput.getValue()==null || ((String)uiInput.getValue()).length()==0) return;
37 UIComponent uiComponent = (UIComponent) uiInput ;
38 UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class) ;
39 String label;
40 try{
41 label = uiForm.getLabel(uiInput.getName());
42 } catch(Exception e) {
43 label = uiInput.getName();
44 }
45 label = label.trim();
46 if(label.charAt(label.length() - 1) == ':') label = label.substring(0, label.length() - 1);
47 if (((String)uiInput.getValue()).charAt(0) == '0') {
48 Object[] args = { label, uiInput.getBindingField() };
49 throw new MessageException(new ApplicationMessage("ZeroValidator.msg.Invalid-number", args)) ;
50 }
51 }
52
53 }