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.util.LoginUtilities;
32  
33  /**
34   * This is the LoginForm Struts Form. It is used by Login form.
35   * 
36   * @author ready
37   * 
38   */
39  public class CustomFieldValueForm extends ValidatorForm {
40  	/**
41  	 * 
42  	 */
43  	private static final long serialVersionUID = 1L;
44  	private String action;
45  
46  	private Integer id;
47  
48  	private String value;
49  	private Integer sortOrder;
50  	// let's try to put String,String here:
51  	private HashMap<String, String> translations = new HashMap<String, String>();
52  
53  	// private Map<String, String> translations;
54  
55  	public String getAction() {
56  		return action;
57  	}
58  
59  	public void setAction(String action) {
60  		this.action = action;
61  	}
62  
63  	public Integer getId() {
64  		return id;
65  	}
66  
67  	public void setId(Integer id) {
68  		this.id = id;
69  	}
70  
71  	// let's try to put String,String here:
72  	public HashMap<String, String> getTranslations() {
73  		return translations;
74  	}
75  
76  	// let's try to put String,String here:
77  	public void setTranslations(HashMap<String, String> translations) {
78  		this.translations = translations;
79  	}
80  
81  	/**
82  	 * get localization in base locale
83  	 * @return
84  	 */
85  	private String getBaseTranslation() {
86  		return translations.get(ITrackerResources.BASE_LOCALE);
87  	}
88  	
89  	public String getValue() {
90  		return value;
91  	}
92  
93  	public void setValue(String value) {
94  		this.value = value;
95  	}
96  
97  	public void reset(ActionMapping mapping, HttpServletRequest request) {
98  		
99  	}
100 
101 	public void setSortOrder(Integer sortOrder) {
102 		this.sortOrder = sortOrder;
103 	}
104 
105 	public Integer getSortOrder() {
106 		return sortOrder;
107 	}
108 	
109 	public ActionErrors validate(ActionMapping mapping,
110 			HttpServletRequest request) {
111 		ActionErrors errors = super.validate(mapping, request);
112 
113 		// TODO: setup request env for validation output
114 		if (null == getBaseTranslation() || "".equals(getBaseTranslation().trim())) {
115 			errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.validate.required", 
116 					ITrackerResources.getString("itracker.web.attr.baselocale", LoginUtilities.getCurrentLocale(request))));
117 		}
118 		return errors;
119 	}
120 
121 
122 }