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 java.util.MissingResourceException;
20 import java.util.ResourceBundle;
21
22 import org.exoplatform.portal.webui.util.Util;
23 import org.exoplatform.services.cms.templates.TemplateService;
24 import org.exoplatform.web.application.ApplicationMessage;
25 import org.exoplatform.webui.core.UIComponent;
26 import org.exoplatform.webui.exception.MessageException;
27 import org.exoplatform.webui.form.UIForm;
28 import org.exoplatform.webui.form.UIFormInput;
29
30
31
32
33
34
35
36
37
38
39 public class MandatoryValidator extends org.exoplatform.webui.form.validator.MandatoryValidator {
40
41 @SuppressWarnings("unchecked")
42 public void validate(UIFormInput uiInput) throws Exception {
43 if((uiInput.getValue() != null) && ((String)uiInput.getValue()).trim().length() > 0) {
44 return ;
45 }
46
47 UIComponent uiComponent = (UIComponent) uiInput ;
48 UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class) ;
49 String templatePath = uiForm.getTemplate();
50 String nodetypeName = "";
51 String[] temps = templatePath.split("/");
52 for (String temp : temps){
53 if (temp.contains("_fg_n")) {
54 nodetypeName = temp;
55 break;
56 }
57 }
58 TemplateService templateService = uiForm.getApplicationComponent(TemplateService.class);
59 String nodetypeLabel = templateService.getTemplateLabel(nodetypeName).trim();
60 ResourceBundle res = Util.getPortalRequestContext().getApplicationResourceBundle();
61 String label = "";
62 try {
63 label = res.getString(nodetypeLabel + ".label." + uiInput.getName());
64 } catch (MissingResourceException e) {
65 label = uiInput.getName();
66 }
67 Object[] args = {label, uiInput.getBindingField() } ;
68 throw new MessageException(new ApplicationMessage("EmptyFieldValidator.msg.empty-input", args, ApplicationMessage.WARNING)) ;
69 }
70 }