1 16 package com.blandware.atleap.webapp.action.core.grid; 17 18 import com.blandware.atleap.common.util.ConvertUtil; 19 import com.blandware.atleap.webapp.form.core.NumberFilterForm; 20 import com.blandware.atleap.webapp.taglib.core.grid.util.FilterConditions; 21 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid; 22 import com.blandware.atleap.webapp.taglib.core.grid.util.NumberFilter; 23 import com.blandware.atleap.webapp.taglib.core.util.TaglibConstants; 24 import org.apache.struts.action.ActionForm; 25 import org.apache.struts.action.ActionForward; 26 import org.apache.struts.action.ActionMapping; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.http.HttpSession ; 31 32 50 public final class NumberFilterAction extends com.blandware.atleap.webapp.action.core.grid.BaseGridAction { 51 52 61 public ActionForward execute(ActionMapping mapping, ActionForm form, 62 HttpServletRequest request, HttpServletResponse response) { 63 64 HttpSession session = request.getSession(); 65 NumberFilterForm numberFilterForm = (com.blandware.atleap.webapp.form.core.NumberFilterForm) form; 66 67 String fieldName = numberFilterForm.getFieldName(); 68 String rowIterators = numberFilterForm.getRowIterators(); 69 String gridName = numberFilterForm.getGridName(); 70 Grid grid = getGridByName(gridName, session); 71 72 if ( grid == null ) { 73 if ( log.isErrorEnabled() ) { 74 String errorMessage = "No grid with name " + gridName + " could be found in session"; 75 log.error(errorMessage); 76 } 77 return mapping.findForward("filterError"); 78 } 79 80 NumberFilter filter = new NumberFilter(fieldName); 81 filter.setRowIterators(ConvertUtil.convertStringToList(rowIterators, ",", true)); 82 83 String firstCondition = numberFilterForm.getFirstCondition(); 84 String firstValue = numberFilterForm.getFirstValue(); 85 String secondCondition = numberFilterForm.getSecondCondition(); 86 String secondValue = numberFilterForm.getSecondValue(); 87 String logicCopula = numberFilterForm.getLogicCopula(); 88 89 92 if ( numberFilterForm.getClearFilter() != null ) { 93 grid.removeFilter(filter); 94 if ( log.isDebugEnabled() ) { 95 log.debug("Filter for field '" + fieldName + "' was removed from grid"); 96 } 97 } else { 98 if ( firstCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL) || firstCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL) ) { 99 filter.createFirstClause(firstCondition, null); 100 } else if ( firstValue != null || firstValue.length() != 0 ) { 101 filter.createFirstClause(firstCondition, Float.valueOf(firstValue)); 102 } else { 103 if ( secondCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL) || secondCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL) ) { 104 filter.createFirstClause(secondCondition, null); 105 } else if ( secondValue != null || secondValue.length() != 0 ) { 106 filter.createFirstClause(secondCondition, Float.valueOf(secondValue)); 107 } 108 } 109 110 if ( !secondCondition.equalsIgnoreCase(FilterConditions.CONDITION_NOT_SET) ) { 111 if ( secondCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL) || secondCondition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL) ) { 112 filter.createSecondClause(secondCondition, null); 113 } else if ( secondValue != null && secondValue.length() != 0 ) { 114 filter.createSecondClause(secondCondition, Float.valueOf(secondValue), logicCopula); 115 } 116 } 117 grid.addFilter(filter); 118 if ( log.isDebugEnabled() ) { 119 log.debug("New NumberFilter added to grid '" + gridName + "' for field '" + fieldName + "'. Clause is: " + filter.getClause()); 120 } 121 122 } 123 124 saveGrid(grid, session); 125 request.setAttribute(TaglibConstants.PAGE_URL, numberFilterForm.getPageUrl()); 126 return mapping.findForward("filterReturn"); 127 } 128 } | Popular Tags |