KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > form > core > DateFilterForm


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.form.core;
17
18 import com.blandware.atleap.common.util.DateUtil;
19 import com.blandware.atleap.webapp.taglib.core.grid.util.FilterConditions;
20 import org.apache.struts.Globals;
21 import org.apache.struts.action.ActionErrors;
22 import org.apache.struts.action.ActionMapping;
23 import org.apache.struts.action.ActionMessage;
24
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import java.text.SimpleDateFormat JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.Locale JavaDoc;
29
30 /**
31  * <p>Form bean for date filter
32  * </p>
33  * <p><a HREF="DateFilterForm.java.htm"><i>View Source</i></a></p>
34  * <p/>
35  *
36  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
37  * @version $Revision: 1.9 $ $Date: 2005/08/04 17:25:15 $
38  * @struts.form name="dateFilterForm"
39  */

40 public class DateFilterForm extends BaseFilterForm {
41
42     protected String JavaDoc firstCondition = FilterConditions.DATE_EQUAL;
43     protected String JavaDoc firstValue = null;
44     protected String JavaDoc secondCondition = FilterConditions.CONDITION_NOT_SET;
45     protected String JavaDoc secondValue = null;
46     protected String JavaDoc logicCopula = FilterConditions.LOGIC_COPULA_AND;
47
48
49     /**
50      * Creates the new instance of DateFilterForm
51      */

52     public DateFilterForm() {
53     }
54
55     /**
56      * Returns first condition
57      *
58      * @return first condition
59      */

60     public String JavaDoc getFirstCondition() {
61         return firstCondition;
62     }
63
64     /**
65      * Sets first condition
66      *
67      * @param firstCondition first condition to set
68      */

69     public void setFirstCondition(String JavaDoc firstCondition) {
70         this.firstCondition = firstCondition;
71     }
72
73     /**
74      * Returns value attached to first condition
75      *
76      * @return value attached to first condition
77      */

78     public String JavaDoc getFirstValue() {
79         return firstValue;
80     }
81
82     /**
83      * Sets value attached to first condition
84      *
85      * @param firstValue value attached to first condition
86      * @struts.validator type="required, customdate"
87      * @struts.validator-args arg0resource="core.grid.filter.firstValue"
88      */

89     public void setFirstValue(String JavaDoc firstValue) {
90         this.firstValue = firstValue;
91     }
92
93     /**
94      * Returns second condition
95      *
96      * @return second condition
97      */

98     public String JavaDoc getSecondCondition() {
99         return secondCondition;
100     }
101
102     /**
103      * Sets second condition
104      *
105      * @param secondCondition second condition to set
106      */

107     public void setSecondCondition(String JavaDoc secondCondition) {
108         this.secondCondition = secondCondition;
109     }
110
111     /**
112      * Returns value attached to second condition
113      *
114      * @return value attached to second condition
115      */

116     public String JavaDoc getSecondValue() {
117         return secondValue;
118     }
119
120     /**
121      * Sets value attached to second condition
122      *
123      * @param secondValue value attached to second condition
124      * @struts.validator type="customdate"
125      * @struts.validator-args arg0resource="core.grid.filter.firstValue"
126      */

127     public void setSecondValue(String JavaDoc secondValue) {
128         this.secondValue = secondValue;
129     }
130
131     /**
132      * Returns logic copula between conditions
133      *
134      * @return logic copula
135      */

136     public String JavaDoc getLogicCopula() {
137         return logicCopula;
138     }
139
140     /**
141      * Sets logic copula between conditions
142      *
143      * @param logicCopula logic copula
144      */

145     public void setLogicCopula(String JavaDoc logicCopula) {
146         this.logicCopula = logicCopula;
147     }
148
149     /**
150      * Resets all properties to their default values
151      *
152      * @param mapping The ActionMapping used to select this instance
153      * @param request The non-http request we are proceeding
154      */

155     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
156         super.reset(mapping, request);
157         this.firstCondition = FilterConditions.DATE_EQUAL;
158         Locale JavaDoc locale = (Locale JavaDoc) request.getSession().getAttribute(Globals.LOCALE_KEY);
159         this.firstValue = new SimpleDateFormat JavaDoc(DateUtil.getDatePattern(locale), locale).format(new Date JavaDoc());
160         this.secondCondition = FilterConditions.CONDITION_NOT_SET;
161         this.secondValue = null;
162         this.clearFilter = null;
163         logicCopula = FilterConditions.LOGIC_COPULA_AND;
164     }
165
166     /**
167      * Form validation
168      *
169      * @param mapping The ActionMapping used to select this instance
170      * @param request The non-http request we are proceeding
171      * @return Instance of ActionErrors contains all validation errors
172      */

173     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
174         ActionErrors errors = super.validate(mapping, request);
175
176         if ( clearFilter == null ) {
177
178             boolean notSet = secondCondition.equalsIgnoreCase(FilterConditions.CONDITION_NOT_SET);
179             boolean isNull = secondCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL);
180             boolean isNotNull = secondCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL);
181
182             if ( !notSet && !isNull && !isNotNull ) {
183                 if ( secondValue == null || secondValue.length() == 0 ) {
184                     errors.add("secondValue", new ActionMessage("core.grid.filter.errors.secondValueRequired"));
185                 }
186             }
187         } else {
188             errors = new ActionErrors();
189         }
190         return errors;
191     }
192
193
194 }
Popular Tags