org.apache.beehive.netui.tags.html
Class FormatString

Object
  extended by SimpleTagSupport
      extended by AbstractSimpleTag
          extended by FormatTag
              extended by FormatString
All Implemented Interfaces:
JspTag, SimpleTag, INetuiTag

public class FormatString
extends FormatTag

A formatter used to format strings. FormatString uses the following pattern syntax:

The '#' character gets replaced by the next character in the string getting formatted, while other characters get put in as literals. For example:

String "5555555555" with pattern "(###)###-####" would result in: (555)555-5555.

The '*' character will display all characters in the string at that point in the pattern. For example:

String "123456" with pattern "#-*!" would result in: 1-23456!

If a result with a '#' pr '*' character showing is desired, the '#' or '*' needs to be escaped with the '$' character. For example:

String "ABCD" with pattern "$#-####" would result in: #-ABCD.

To show a '$' in the result, the '$' character needs to be escaped. For example:

String "1234" with pattern "$$#,###" would result in: $1,234

If the truncate attribute is set to "true", characters in the string that exceed the pattern will be dropped. Otherwise, they will be appended to the end of the formatted string.

Example
In this sample, the String "2125555555" will be formatted to this form: (212)555-5555.
    <netui:span value="2125555555">
        <netui:formatString pattern="phone (###) ###-####"/>
    </netui:span> 

Nested Class Summary
static class FormatString.StringFormatter
          Internal FormatTag.Formatter which performs its own string parsing and formatting.
 
Nested classes/interfaces inherited from class FormatTag
FormatTag.Formatter
 
Field Summary
protected  boolean truncate
           
 
Fields inherited from class FormatTag
_pattern
 
Constructor Summary
FormatString()
           
 
Method Summary
 void doTag()
          Create the internal Formatter instance and perform the formatting.
 String getTagName()
          Return the name of the Tag.
 void setTruncate(boolean truncate)
          Sets whether or not pattern-exceeding characters should be dropped.
 
Methods inherited from class FormatTag
getLocale, setCountry, setLanguage, setPattern
 
Methods inherited from class AbstractSimpleTag
getBufferBody, getHtmlTag, getIdForTagId, getInlineError, getPageContext, getScriptReporter, getUserLocale, hasErrors, registerTagError, registerTagError, reportErrors, rewriteName, setNonEmptyValueAttribute, setRequiredValueAttribute, write
 
Methods inherited from class SimpleTagSupport
findAncestorWithClass, getJspBody, getJspContext, getParent, setJspBody, setJspContext, setParent
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

truncate

protected boolean truncate
Constructor Detail

FormatString

public FormatString()
Method Detail

getTagName

public String getTagName()
Return the name of the Tag.

Specified by:
getTagName in interface INetuiTag
Specified by:
getTagName in class AbstractSimpleTag
Returns:
the name of the tag.

setTruncate

public void setTruncate(boolean truncate)
Sets whether or not pattern-exceeding characters should be dropped.

Parameters:
truncate - "true" or "false"

doTag

public void doTag()
           throws JspException
Create the internal Formatter instance and perform the formatting.

Specified by:
doTag in interface SimpleTag
Overrides:
doTag in class SimpleTagSupport
Throws:
JspException - if a JSP exception has occurred