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 java.util.HashMap;
22  
23  import javax.servlet.http.HttpServletRequest;
24  
25  import org.apache.struts.action.ActionErrors;
26  import org.apache.struts.action.ActionMapping;
27  import org.apache.struts.action.ActionMessage;
28  import org.apache.struts.action.ActionMessages;
29  import org.apache.struts.validator.ValidatorForm;
30  import org.itracker.core.resources.ITrackerResources;
31  import org.itracker.web.actions.admin.configuration.EditCustomFieldActionUtil;
32  import org.itracker.web.util.LoginUtilities;
33  
34  /**
35   * This is the Struts Form. It is used by action.
36   * 
37   * @author ready
38   * 
39   */
40  @SuppressWarnings("serial")
41  public class CustomFieldForm extends ValidatorForm {
42  	String action = null;
43  	Integer id = null;
44  	Integer fieldType = null;
45  	String required = null;
46  	String dateFormat = null;
47  	String sortOptionsByName = null;
48  	String value = null;
49  //	private String base_locale;
50  	HashMap<String, String> translations = new HashMap<String, String>();
51  
52  
53  	/*
54  	 * public void reset(ActionMapping mapping, HttpServletRequest request) {
55  	 * action = null; id = null; fieldType = null; required= null; dateFormat=
56  	 * null; sortOptionsByName= null; value= null; translations = null;
57  	 *  }
58  	 */
59  	@Override
60  	public ActionErrors validate(ActionMapping mapping,
61  			HttpServletRequest request) {
62  		ActionErrors errors = super.validate(mapping, request);
63  		
64  		if (null == getBaseTranslation() || "".equals(getBaseTranslation().trim())) {
65  			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.validate.required", 
66  					ITrackerResources.getString("itracker.web.attr.baselocale", LoginUtilities.getCurrentLocale(request))));
67  		}
68  		
69  		EditCustomFieldActionUtil.setRequestEnv(request, this);
70  		return errors;
71  	}
72  
73  
74  	@Override
75  	public void reset(ActionMapping mapping, HttpServletRequest request) {
76  		super.reset(mapping, request);
77  	}
78  	
79  	public String getAction() {
80  		return action;
81  	}
82  
83  	public void setAction(String action) {
84  		this.action = action;
85  	}
86  
87  	public String getDateFormat() {
88  		return dateFormat;
89  	}
90  
91  	public void setDateFormat(String dateFormat) {
92  		this.dateFormat = dateFormat;
93  	}
94  
95  	public Integer getFieldType() {
96  		return fieldType;
97  	}
98  
99  	public void setFieldType(Integer fieldType) {
100 		this.fieldType = fieldType;
101 	}
102 
103 	public Integer getId() {
104 		return id;
105 	}
106 
107 	public void setId(Integer id) {
108 		this.id = id;
109 	}
110 
111 	public String getRequired() {
112 		return required;
113 	}
114 
115 	public void setRequired(String required) {
116 		this.required = required;
117 	}
118 
119 	public String getSortOptionsByName() {
120 		return sortOptionsByName;
121 	}
122 
123 	public void setSortOptionsByName(String sortOptionsByName) {
124 		this.sortOptionsByName = sortOptionsByName;
125 	}
126 
127 	public HashMap<String, String> getTranslations() {
128 		return translations;
129 	}
130 
131 	public void setTranslations(HashMap<String, String> translations) {
132 		this.translations = translations;
133 	}
134 
135 	public String getValue() {
136 		return value;
137 	}
138 
139 	public void setValue(String value) {
140 		this.value = value;
141 	}
142 
143 	/**
144 	 * get localization in base locale
145 	 * @return
146 	 */
147 	private String getBaseTranslation() {
148 		return translations.get(ITrackerResources.BASE_LOCALE);
149 	}
150 
151 	
152 }