org.dbforms.taglib
Class DbFilterTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.dbforms.taglib.AbstractScriptHandlerTag
              extended by org.dbforms.taglib.AbstractDbBaseHandlerTag
                  extended by org.dbforms.taglib.DbFilterTag
All Implemented Interfaces:
Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.Tag, javax.servlet.jsp.tagext.TryCatchFinally

public class DbFilterTag
extends AbstractDbBaseHandlerTag
implements javax.servlet.jsp.tagext.TryCatchFinally

custom tag that build up a set of sql filters. Create a set of sql filter conditions, letting user select which one will be applied. A filter tag contains one or more filterCondition tag. Each filterCondition represent a sql condition and is identified by its label. In the body of the filterCondition tag there is the piece of SQL code that we want to insert in the where clause, the character ? act like a placeholder, so a ? in the sql code will be substituted with the some user input. To tell the system what type of user input we want, the last tag is used, the filterValue tag. Each ? found in body will be subsituted by its corresponding filterValue tag. With the "type" attribute of this tag you can select the input more. Selecting "text", a filterValue will render an html input tag, with "select" you'll have an html select, and so on. An example is like this:

  <db:filter>
      <db:filterCondition label="author name like">
          NAME LIKE '%?%'
          <db:filterValue type="timestamp" useJsCalendar="true" />
      </db:filterCondition>
      <db:filterCondition label="ID > V1 AND ID < V2">
          AUTHOR_ID >= ? AND AUTHOR_ID <= ?
          <db:filterValue label="V1" type="numeric"/>
          <db:filterValue label="V2" type="numeric"/>
      </db:filterCondition>
      <db:filterCondition label="author = ">
          NAME = '?'
          <db:filterValue type="select">
              <db:queryData name="q1" query="select distinct name as n1, name as n2 from author where AUTHOR_ID < 100 order by name"/>
          </db:filterValue>
      </db:filterCondition>
      <db:filterCondition label="now is after date">
          CURRENT_DATE > ?
          <db:filterValue type="date" useJsCalendar="true" />
      </db:filterCondition>
      <db:filterCondition label="filter without user input">
          AUTHOR_ID > 10
      </db:filterCondition>
  </db:filter>
 
This structure will be rendered as a html select element to select the condition the you want to apply. On the onchange event there is a submit, so the page reload with the input elements of the condition that you have selected. After all input elements, there are two buttons, one to apply the condition, one to unset the current applied condition.

Internals:

filter_[tableId]
prefix that all the parameters created by this tag have.
filter_[tableId]_sel
index of the currently selected condition
filter_[tableId]_cond_[condId]
text of the currently selected condition
filter_[tableId]_cond_[condId]_value_[valueId]
current value of the input tag corresponding to the filterValue tag identified by [valueId]
filter_[tableId]_cond_[condId]_valuetype_[valueId]
type of the value identified by [valueId]

Reading data from request, and update corrispondently the sqlFilter attribute of DbFormTag is done in the static method generateSqlFilter, which produce in output a valid filter string. This method is called in DbFormTag's method doStartTag, setting with it the sqlFilter attribute value. The only other changes needed in DbFormTag's doStartTag is the nullifing of the firstPosition and lastPosition variables that normally contain the current position in the case of applying of a filter (.i.e. when user press the set button, and so the filter_<tableId>_set parameter is found in request). This is needed because here we must force the goto event to move to the first avalilable row.

Version:
$Revision: 1.30 $
Author:
Sergio Moretti
See Also:
Serialized Form

Field Summary
protected static String FLT_COND
          DOCUMENT ME!
protected static String FLT_PREFIX
          DOCUMENT ME!
protected static String FLT_SEARCHALGO
          DOCUMENT ME!
protected static String FLT_SEL
          DOCUMENT ME!
protected static String FLT_SET
          DOCUMENT ME!
protected static String FLT_VALUE
          DOCUMENT ME!
protected static String FLT_VALUETYPE
          DOCUMENT ME!
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
DbFilterTag()
           
 
Method Summary
protected  int addCondition(DbFilterConditionTag condition)
          add a condition object to the list.
 int doEndTag()
          here we read information from nested tags and we render output to the page.
 void doFinally()
          reset tag state
 int doStartTag()
          initialize environment
protected  String getFilterName()
          filter's parameters prefix in request
protected static String getFilterName(int tableId)
          filter prefix
static String getSqlFilter(HttpServletRequest request, int tableId)
          return the currently setted filter condition, reading it from request.
static FieldValue[] getSqlFilterParams(HttpServletRequest request, int tableId)
          return the parametes of the currently setted filter condition, reading it from request.
protected  int getTableId()
          return tableId of the parent dbform tag
 void setDisabledCaption(String string)
          DOCUMENT ME!
 void setSetCaption(String string)
          DOCUMENT ME!
 void setSetStyleClass(String string)
          DOCUMENT ME!
 void setSize(String string)
          DOCUMENT ME!
 void setUnsetCaption(String string)
          DOCUMENT ME!
 void setUnsetStyleClass(String string)
          DOCUMENT ME!
 
Methods inherited from class org.dbforms.taglib.AbstractDbBaseHandlerTag
customFormat, escapeHTML, getCustomFormatter, getDefaultValue, getEscaper, getEscaperClass, getField, getFieldObject, getFieldValue, getFormattedFieldValue, getFormatter, getFormFieldDefaultValue, getFormFieldName, getFormFieldValue, getLocale, getMaxlength, getName, getParentForm, getPattern, getReadOnlyStyleClass, getStyleClass, hasReadOnlySet, renderOldValueHtmlInputField, renderPatternHtmlInputField, setCustomFormatter, setDefaultValue, setEscaperClass, setField, setFieldName, setMaxlength, setNullFieldValue, setParent, setPattern, setReadOnly, setReadOnlyStyleClass, typicalDefaultValue, writeOutSpecialValues
 
Methods inherited from class org.dbforms.taglib.AbstractScriptHandlerTag
doCatch, getAccessKey, getConfig, getOnBlur, getOnChange, getOnClick, getOnDblClick, getOnFocus, getOnKeyDown, getOnKeyPress, getOnKeyUp, getOnMouseDown, getOnMouseMove, getOnMouseOut, getOnMouseOver, getOnMouseUp, getOnSelect, getStyle, getTabIndex, getTitle, prepareEventHandlers, prepareStyles, setAccessKey, setOnBlur, setOnChange, setOnClick, setOnDblClick, setOnFocus, setOnKeyDown, setOnKeyPress, setOnKeyUp, setOnMouseDown, setOnMouseMove, setOnMouseOut, setOnMouseOver, setOnMouseUp, setOnSelect, setStyle, setStyleClass, setTabIndex, setTitle
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doAfterBody, doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.TryCatchFinally
doCatch
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext
 

Field Detail

FLT_COND

protected static final String FLT_COND
DOCUMENT ME!

See Also:
Constant Field Values

FLT_PREFIX

protected static final String FLT_PREFIX
DOCUMENT ME!

See Also:
Constant Field Values

FLT_SEL

protected static final String FLT_SEL
DOCUMENT ME!

See Also:
Constant Field Values

FLT_SET

protected static final String FLT_SET
DOCUMENT ME!

See Also:
Constant Field Values

FLT_VALUE

protected static final String FLT_VALUE
DOCUMENT ME!

See Also:
Constant Field Values

FLT_VALUETYPE

protected static final String FLT_VALUETYPE
DOCUMENT ME!

See Also:
Constant Field Values

FLT_SEARCHALGO

protected static final String FLT_SEARCHALGO
DOCUMENT ME!

See Also:
Constant Field Values
Constructor Detail

DbFilterTag

public DbFilterTag()
Method Detail

getSqlFilter

public static String getSqlFilter(HttpServletRequest request,
                                  int tableId)
return the currently setted filter condition, reading it from request.

Parameters:
request -
tableId -
Returns:
filter string

getSqlFilterParams

public static FieldValue[] getSqlFilterParams(HttpServletRequest request,
                                              int tableId)
return the parametes of the currently setted filter condition, reading it from request.

Parameters:
request -
tableId -
Returns:
filter string

setDisabledCaption

public void setDisabledCaption(String string)
DOCUMENT ME!

Parameters:
string -

setSetCaption

public void setSetCaption(String string)
DOCUMENT ME!

Parameters:
string -

setSize

public void setSize(String string)
DOCUMENT ME!

Parameters:
string -

setUnsetCaption

public void setUnsetCaption(String string)
DOCUMENT ME!

Parameters:
string -

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException
here we read information from nested tags and we render output to the page.

Specified by:
doEndTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException
See Also:
Tag.doEndTag()

doFinally

public void doFinally()
reset tag state

Specified by:
doFinally in interface javax.servlet.jsp.tagext.TryCatchFinally
Overrides:
doFinally in class AbstractDbBaseHandlerTag
See Also:
TryCatchFinally.doFinally()

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
initialize environment

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException
See Also:
Tag.doStartTag()

getFilterName

protected static String getFilterName(int tableId)
filter prefix

Parameters:
tableId -
Returns:

getFilterName

protected String getFilterName()
filter's parameters prefix in request

Returns:

getTableId

protected int getTableId()
return tableId of the parent dbform tag

Returns:

addCondition

protected int addCondition(DbFilterConditionTag condition)
add a condition object to the list. Called by nested DbFilterConditionTag

Parameters:
condition - to add
Returns:
index of the newly added condition

setSetStyleClass

public void setSetStyleClass(String string)
DOCUMENT ME!

Parameters:
string -

setUnsetStyleClass

public void setUnsetStyleClass(String string)
DOCUMENT ME!

Parameters:
string -


Copyright © 2002-2006 DbForms. All Rights Reserved.