CLRA 0.1.2

com.clra.web
Class NameSelectorTag

java.lang.Object
  |
  +--javax.servlet.jsp.tagext.TagSupport
        |
        +--com.clra.web.NameSelectorTag
All Implemented Interfaces:
Serializable, javax.servlet.jsp.tagext.Tag

public class NameSelectorTag
extends javax.servlet.jsp.tagext.TagSupport

Allows the user to choose a group of items, selected by the first letter of their name.

Selection is case-insensitive and limited to 8 predefined groups, like the buttons on a telephone:

  1. ABC - names less than 'D'
  2. DEF - names between 'D' and 'F'
  3. GHI - names between 'G' and 'I'
  4. JKL - names between 'J' and 'L'
  5. MNO - names between 'M' and 'O'
  6. PQRS - names between 'P' and 'S'
  7. TUV - names between 'T' and 'V'
  8. WXYZ - names greater than or equal to 'W'
Note that the first group, ABC, may contain names like "3Com", whereas the last group, WXYZ, may contain names like "Ėtvos". Also note that the group is indexed from '2', not '0'.

Version:
$Revision: 1.2 $ $Date: 2002/02/18 18:06:41 $
Author:
Rick Hall
See Also:
Serialized Form

Field Summary
protected static org.apache.struts.util.MessageResources messages
          The message resources for this package
protected  String page
          The context-relative URI
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
NameSelectorTag()
           
 
Method Summary
protected  String createLink(int group, javax.servlet.http.HttpServletRequest request)
          Creates a link from the currentGroup request
protected  String createLink(int group, String contextPath, String page)
          Create a link from the specified page
protected  String createQueryString(int group, Hashtable queryParams)
          Form a query string from current parameter and the specified group
protected  void doEndLink()
           
 int doEndTag()
          Render the end of the selector
protected  void doGroupLeadingSeparationText(int unused)
          Writes the text that separates group links
protected  void doGroupLink(int group)
          Write a group link
protected  void doGroupLinks()
          Writes an alphabet's worth of group links
protected  void doGroupText(int group)
          Writes a Integer-based group (2 - 9) as user-friendly text
protected  void doGroupTrailingSeparationText(int unused)
          Writes the text that separates group links
protected  void doStartLink(int group)
           
 int doStartTag()
          Render the beginning of the selector
 Integer getCurrentGroup()
          Return the currently selected group (2 - 9, or null)
 String getPage()
          Return the context-relative URI
static Integer groupFromContext(javax.servlet.jsp.PageContext context)
          A utility which determines what group should be currently selected based on the page context.
protected static Map groups()
          The groups used by this selector
 void release()
          Release any acquired resources.
static void resetGroupInContexts(javax.servlet.jsp.PageContext context, Integer group)
          A utility which resets request and session attributes so that only the session attribute AN_GROUP holds the currently selected name.
 void setCurrentGroup(Integer currentGroup)
          Set the currently selected group (2 - 9, or null)
 void setPage(String page)
          Set the context-relative URI
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messages

protected static org.apache.struts.util.MessageResources messages
The message resources for this package

page

protected String page
The context-relative URI
Constructor Detail

NameSelectorTag

public NameSelectorTag()
Method Detail

groups

protected static Map groups()
The groups used by this selector

getPage

public String getPage()
Return the context-relative URI

setPage

public void setPage(String page)
Set the context-relative URI

getCurrentGroup

public Integer getCurrentGroup()
Return the currently selected group (2 - 9, or null)

setCurrentGroup

public void setCurrentGroup(Integer currentGroup)
                     throws javax.servlet.jsp.JspException
Set the currently selected group (2 - 9, or null)

groupFromContext

public static Integer groupFromContext(javax.servlet.jsp.PageContext context)
A utility which determines what group should be currently selected based on the page context. The algorithm is:
  1. Check for a request parameter named INameList.AN_GROUP. If found, and it is a valid Integer in the range 2 - 9, use it.
  2. Check for a request attribute named INameList.AN_GROUP. If found, and it is valid, use it.
  3. Check for a session attribute named INameList.AN_GROUP. If found, and it is valid, use it.
  4. If a valid group hasn't been determined yet, return the index of the first group, ABC (index 2).

resetGroupInContexts

public static void resetGroupInContexts(javax.servlet.jsp.PageContext context,
                                        Integer group)
A utility which resets request and session attributes so that only the session attribute AN_GROUP holds the currently selected name. The algorithm is:
  1. Check for a request attribute named INameList.AN_GROUP. If found, remove it.
  2. Check for a session attribute named INameList.AN_GROUP. If found, reset to the specified value; otherwise create and set it.
If the specified name is invalid (not between 2 - 9, inclusive), no action is taken and an error is logged.

createQueryString

protected String createQueryString(int group,
                                   Hashtable queryParams)
Form a query string from current parameter and the specified group

createLink

protected String createLink(int group,
                            String contextPath,
                            String page)
                     throws javax.servlet.jsp.JspException
Create a link from the specified page

createLink

protected String createLink(int group,
                            javax.servlet.http.HttpServletRequest request)
Creates a link from the currentGroup request

doStartLink

protected void doStartLink(int group)
                    throws javax.servlet.jsp.JspException

doEndLink

protected void doEndLink()
                  throws javax.servlet.jsp.JspException

doGroupText

protected void doGroupText(int group)
                    throws javax.servlet.jsp.JspException
Writes a Integer-based group (2 - 9) as user-friendly text

doGroupLeadingSeparationText

protected void doGroupLeadingSeparationText(int unused)
                                     throws javax.servlet.jsp.JspException
Writes the text that separates group links

doGroupTrailingSeparationText

protected void doGroupTrailingSeparationText(int unused)
                                      throws javax.servlet.jsp.JspException
Writes the text that separates group links

doGroupLink

protected void doGroupLink(int group)
                    throws javax.servlet.jsp.JspException
Write a group link

doGroupLinks

protected void doGroupLinks()
                     throws javax.servlet.jsp.JspException
Writes an alphabet's worth of group links

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Render the beginning of the selector
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException
Render the end of the selector
Overrides:
doEndTag in class javax.servlet.jsp.tagext.TagSupport

release

public void release()
Release any acquired resources.
Overrides:
release in class javax.servlet.jsp.tagext.TagSupport

CLRA 0.1.2