KickJava   Java API By Example, From Geeks To Geeks.

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


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 string filter
27  * </p>
28  * <p><a HREF="StringFilterForm.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.9 $ $Date: 2005/08/04 17:25:16 $
33  * @struts.form name="stringFilterForm"
34  */

35 public class StringFilterForm extends BaseFilterForm {
36
37     protected String JavaDoc firstCondition = FilterConditions.STRING_CONTAINS;
38     protected String JavaDoc firstValue = "";
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 StringFilterForm
46      */

47     public StringFilterForm() {
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      */

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

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

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

109     public String JavaDoc getSecondValue() {
110         return secondValue;
111     }
112
113     /**
114      * Sets value attached to second condition
115      *
116      * @param secondValue
117      */

118     public void setSecondValue(String JavaDoc secondValue) {
119         this.secondValue = secondValue;
120     }
121
122     /**
123      * Returns logic copula between conditions
124      *
125      * @return logic copula
126      */

127     public String JavaDoc getLogicCopula() {
128         return logicCopula;
129     }
130
131     /**
132      * Sets logic copula between conditions
133      *
134      * @param logicCopula logic copula
135      */

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

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

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