1 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 ; 26 import java.text.SimpleDateFormat ; 27 import java.util.Date ; 28 import java.util.Locale ; 29 30 40 public class DateFilterForm extends BaseFilterForm { 41 42 protected String firstCondition = FilterConditions.DATE_EQUAL; 43 protected String firstValue = null; 44 protected String secondCondition = FilterConditions.CONDITION_NOT_SET; 45 protected String secondValue = null; 46 protected String logicCopula = FilterConditions.LOGIC_COPULA_AND; 47 48 49 52 public DateFilterForm() { 53 } 54 55 60 public String getFirstCondition() { 61 return firstCondition; 62 } 63 64 69 public void setFirstCondition(String firstCondition) { 70 this.firstCondition = firstCondition; 71 } 72 73 78 public String getFirstValue() { 79 return firstValue; 80 } 81 82 89 public void setFirstValue(String firstValue) { 90 this.firstValue = firstValue; 91 } 92 93 98 public String getSecondCondition() { 99 return secondCondition; 100 } 101 102 107 public void setSecondCondition(String secondCondition) { 108 this.secondCondition = secondCondition; 109 } 110 111 116 public String getSecondValue() { 117 return secondValue; 118 } 119 120 127 public void setSecondValue(String secondValue) { 128 this.secondValue = secondValue; 129 } 130 131 136 public String getLogicCopula() { 137 return logicCopula; 138 } 139 140 145 public void setLogicCopula(String logicCopula) { 146 this.logicCopula = logicCopula; 147 } 148 149 155 public void reset(ActionMapping mapping, HttpServletRequest request) { 156 super.reset(mapping, request); 157 this.firstCondition = FilterConditions.DATE_EQUAL; 158 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 159 this.firstValue = new SimpleDateFormat (DateUtil.getDatePattern(locale), locale).format(new Date ()); 160 this.secondCondition = FilterConditions.CONDITION_NOT_SET; 161 this.secondValue = null; 162 this.clearFilter = null; 163 logicCopula = FilterConditions.LOGIC_COPULA_AND; 164 } 165 166 173 public ActionErrors validate(ActionMapping mapping, HttpServletRequest 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 |