View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.web.forms;
20  
21  import org.apache.struts.action.ActionErrors;
22  import org.apache.struts.action.ActionMapping;
23  import org.apache.struts.action.ActionMessage;
24  import org.apache.struts.action.ActionMessages;
25  import org.apache.struts.validator.ValidatorForm;
26  import org.itracker.core.resources.ITrackerResources;
27  import org.itracker.web.util.LoginUtilities;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import java.util.HashMap;
31  import java.util.Map;
32  
33  /**
34   * This is the LoginForm Struts Form. It is used by Login form.
35   *
36   * @author ready
37   */
38  public class CustomFieldValueForm extends ValidatorForm {
39      /**
40       *
41       */
42      private static final long serialVersionUID = 1L;
43      private String action;
44  
45      private Integer id;
46  
47      private String value;
48      private Integer sortOrder;
49      private Map<String, String> translations = new HashMap<>();
50  
51  
52      public String getAction() {
53          return action;
54      }
55  
56      public void setAction(String action) {
57          this.action = action;
58      }
59  
60      public Integer getId() {
61          return id;
62      }
63  
64      public void setId(Integer id) {
65          this.id = id;
66      }
67  
68      // let's try to put String,String here:
69      public Map<String, String> getTranslations() {
70          return translations;
71      }
72  
73      // let's try to put String,String here:
74      public void setTranslations(Map<String, String> translations) {
75          this.translations = translations;
76      }
77  
78      /**
79       * get localization in base locale
80       */
81      private String getBaseTranslation() {
82          return translations.get(ITrackerResources.BASE_LOCALE);
83      }
84  
85      public String getValue() {
86          return value;
87      }
88  
89      public void setValue(String value) {
90          this.value = value;
91      }
92  
93      public void reset(ActionMapping mapping, HttpServletRequest request) {
94  
95      }
96  
97      public void setSortOrder(Integer sortOrder) {
98          this.sortOrder = sortOrder;
99      }
100 
101     public Integer getSortOrder() {
102         return sortOrder;
103     }
104 
105     public ActionErrors validate(ActionMapping mapping,
106                                  HttpServletRequest request) {
107         ActionErrors errors = super.validate(mapping, request);
108 
109         // TODO: setup request env for validation output
110         if (null == getBaseTranslation() || "".equals(getBaseTranslation().trim())) {
111             errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.validate.required",
112                     ITrackerResources.getString("itracker.web.attr.baselocale", LoginUtilities.getCurrentLocale(request))));
113         }
114         return errors;
115     }
116 
117 
118 }