KickJava   Java API By Example, From Geeks To Geeks.

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


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.webapp.taglib.core.grid.util.FilterConditions;
19 import org.apache.struts.action.ActionErrors;
20 import org.apache.struts.action.ActionMapping;
21 import org.apache.struts.action.ActionMessage;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 /**
26  * <p>Form bean for number filter
27  * </p>
28  * <p><a HREF="NumberFilterForm.java.htm"><i>View Source</i></a></p>
29  * <p/>
30  *
31  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
32  * @version $Revision: 1.8 $ $Date: 2005/08/04 17:25:16 $
33  * @struts.form name="numberFilterForm"
34  */

35 public class NumberFilterForm extends BaseFilterForm {
36
37     protected String JavaDoc firstCondition = FilterConditions.NUMBER_EQUAL;
38     protected String JavaDoc firstValue = "0";
39     protected String JavaDoc secondCondition = FilterConditions.CONDITION_NOT_SET;
40     protected String JavaDoc secondValue = null;
41     protected String JavaDoc logicCopula = FilterConditions.LOGIC_COPULA_AND;
42
43
44     /**
45      * Creates the new instance of NumberFilterForm
46      */

47     public NumberFilterForm() {
48     }
49
50     /**
51      * Returns first condition
52      *
53      * @return first condition
54      */

55     public String JavaDoc getFirstCondition() {
56         return firstCondition;
57     }
58
59     /**
60      * Sets first condition
61      *
62      * @param firstCondition first condition to set
63      */

64     public void setFirstCondition(String JavaDoc firstCondition) {
65         this.firstCondition = firstCondition;
66     }
67
68     /**
69      * Returns value attached to first condition
70      *
71      * @return value attached to first condition
72      */

73     public String JavaDoc getFirstValue() {
74         return firstValue;
75     }
76
77     /**
78      * Sets value attached to first condition
79      *
80      * @param firstValue value attached to first condition
81      * @struts.validator type="required, float"
82      * @struts.validator-args arg0resource="core.grid.filter.firstValue"
83      */

84     public void setFirstValue(String JavaDoc firstValue) {
85         this.firstValue = firstValue;
86     }
87
88     /**
89      * Returns second condition
90      *
91      * @return second condition
92      */

93     public String JavaDoc getSecondCondition() {
94         return secondCondition;
95     }
96
97     /**
98      * Sets second condition
99      *
100      * @param secondCondition second condition to set
101      */

102     public void setSecondCondition(String JavaDoc secondCondition) {
103         this.secondCondition = secondCondition;
104     }
105
106     /**
107      * Returns value attached to second condition
108      *
109      * @return value attached to second condition
110      */

111     public String JavaDoc getSecondValue() {
112         return secondValue;
113     }
114
115     /**
116      * Sets value attached to second condition
117      *
118      * @param secondValue value attached to second condition
119      * @struts.validator type="float"
120      * @struts.validator-args arg0resource="core.grid.filter.secondValue"
121      */

122     public void setSecondValue(String JavaDoc secondValue) {
123         this.secondValue = secondValue;
124     }
125
126     /**
127      * Returns logic copula between conditions
128      *
129      * @return logic copula
130      */

131     public String JavaDoc getLogicCopula() {
132         return logicCopula;
133     }
134
135     /**
136      * Sets logic copula between conditions
137      *
138      * @param logicCopula logic copula
139      */

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

150     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
151         super.reset(mapping, request);
152         this.firstCondition = FilterConditions.NUMBER_EQUAL;
153         this.firstValue = "0";
154         this.secondCondition = FilterConditions.CONDITION_NOT_SET;
155         this.secondValue = null;
156         this.clearFilter = null;
157         logicCopula = FilterConditions.LOGIC_COPULA_AND;
158     }
159
160     /**
161      * Form validation
162      *
163      * @param mapping The ActionMapping used to select this instance
164      * @param request The non-http request we are proceeding
165      * @return Instance of ActionErrors contains all validation errors
166      */

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