jp.terasoluna.fw.web.taglib
Class DecimalTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by jp.terasoluna.fw.web.taglib.DecimalTag
All Implemented Interfaces:
java.io.Serializable, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag

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

Implementation class of decimaltag.

Formats and outputs the encoded and decimal value or defines it as scripting variable.

The numerical data to be formatted supports java.math.BigDecimal type or java.lang.String type. In case of java.lang.String type, the string should be parsable by the BigDecimal constructor.

If it cannot be parsed by BigDecimal constructor, NumberFormatException is thrown.


Attribute supported by tag

In DecimalTag, following attributes are supported.

Attribute name Default value Required Execution time format Overview
id None false false It is specified when the formatted string is to be set to scripting variable and not to be output to the response. In case when the formatted string is set to scripting variable, irrespective of whether the filter attribute is specified or not, the special HTML characters are not escaped.
filter true false true Specify whether to escape the special HTML characters at the time of outputting the formatted string. When id attribute is specified, it is ignored.
ignore false false true Specify whether to ignore when the bean, which is specified in name attribute, is not found.If false is specified, JspException is thrown when bean is not found.
name None false true bean name that contains the string to be formatted specified in the property attribute. When property attribute is not specified,the instance specified in name attribute needs to be formatted. In this case, that instance itself should either belong to java.math.BigDecimal type or java.lang.String type. (It can be parsed by BigDecimal constructor after deleting the blank space at the right side) When value attribute is specified, it is ignored.
property None false true Property name which is accessed in bean which is specified in name attribute. When value attribute is specified, it is ignored.
scope (Search order of findAttribute() method) false true Scope to search the bean which is specified in nameattribute.
value None false true String to be formatted. It should be possible to parse the string by the BigDecimal constructor after deleting the white space on the right side. When value attribute is specified, name and property attributes are ignored.
pattern None true true Output format. Output format which is specified in pattern attribute is parsed as pattern of DecimalFormat class. For details, refer to the documents of DecimalFormat class.
scale None false true Number of decimal places after rounding off. When n is specified, it is rounded off to n + 1 decimal place. Round mode is specified in round attribute. When round attribute is not specified, ROUND_HALF_UP(round off) operation is performed by default.
round None false true Round mode. It becomes valid when scale attribute is sepcified.ROUND_HALF_UP(round off) and ROUND_FLOOR(truncate), ROUND_CEILING (round-up)can be set. ROUND_HALF_UP is executed by default.When other than the above three settings are specified, IllegalArgumentException is thrown.
Scripting variable of custom tag

In DecimalTag, following variables are supported.

Variable name Type Valid range Description
Name which is specified in id attribute of custom tag. String After start tag Variable name in case when formatted string is output to a scripting variable and not output in this custom tag.

See Also:
Serialized Form

Field Summary
protected  boolean filter
          Check whether to filter special HTML characters when they are output. Default is true.
protected  java.lang.String id
          Name of scipting variable which can be used on the respective page.
protected  boolean ignore
          Check whether to ignore (nothing is output) when bean is not found. Throws exception when it is not to be ignored. Default is false. (Throw exception).
private static org.apache.commons.logging.Log log
          Log class.
protected  java.lang.String name
          bean name that includes the data to be formatted.
protected  java.lang.String pattern
          Pattern that specifies the output format. It should be same as DecimalFormat.
protected  java.lang.String property
          Property name which is accessed in the specified bean.
protected  java.lang.String round
          Round mode.
protected  int scale
          Number of decimal places after rounding off. When n is specified, it is rounded off to n + 1 decimal place.
protected  java.lang.String scope
          Scope to search the specified bean.
private static long serialVersionUID
          Serial version ID
protected  java.lang.String value
          Value to be formatted(string).
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
pageContext
 
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
DecimalTag()
           
 
Method Summary
 int doStartTag()
          Method which is called at the time of starting tag evaluation.
 boolean getFilter()
          Get the filter to decide whether the special HTML characters are to be filtered.
 java.lang.String getId()
          Fetches the name of scripting variable.
 boolean getIgnore()
          Getignore method to decide whether to ignore when the bean is not found.
 java.lang.String getName()
          Fetches the name of bean that includes the data to be formatted.
 java.lang.String getPattern()
          Fetches the pattern that specifies the output format.
 java.lang.String getProperty()
          Fetches the name of property which is accessed in specified bean.
 java.lang.String getRound()
          Fetches the round mode.
 int getScale()
          Fetches the number of decimal places after rounding off.
 java.lang.String getScope()
          Fetches the scope to search the specified bean.
 java.lang.String getValue()
          Fetches the value to be formatted.
 void release()
          Releases all allocated resources.
 void setFilter(boolean filter)
          setFilter method to decide whether the special HTML characters are to be filtered.
 void setId(java.lang.String id)
          Sets the name of scripting variable.
 void setIgnore(boolean ignore)
          setIgnore method to decide whether to ignore when the bean is not found.
 void setName(java.lang.String name)
          Sets the name of bean that includes the data to be formatted.
 void setPattern(java.lang.String pattern)
          Sets the pattern that specifies the output format.
 void setProperty(java.lang.String property)
          Sets the name of property which is accessed in the specified bean.
 void setRound(java.lang.String round)
          Sets the round mode.
 void setScale(int scale)
          Sets the number of decimal places after rounding off.
 void setScope(java.lang.String scope)
          Sets the scope to search the specified bean.
 void setValue(java.lang.String value)
          Sets the value to be formatted.
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
doAfterBody, doEndTag, findAncestorWithClass, getParent, getValue, getValues, removeValue, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serial version ID

See Also:
Constant Field Values

log

private static org.apache.commons.logging.Log log
Log class.


id

protected java.lang.String id
Name of scripting variable which is available on respective page.


filter

protected boolean filter
Check whether to filter the special HTML characters when they are output. Default is true.


ignore

protected boolean ignore
Check whether to ignore (nothing is output) when bean is not found. Throws exception when it is not ignored. Default is false (Throw an exception).


name

protected java.lang.String name
Name of bean that includes the data to be formatted.


property

protected java.lang.String property
Property name which is accessed in the specified bean.


scope

protected java.lang.String scope
Scope to search the specified bean.


pattern

protected java.lang.String pattern
Pattern to specify the output format. It should be same as DecimalFormat.


value

protected java.lang.String value
Value to be formatted(string).


scale

protected int scale
Number of decimal places after rounding off. When n is specified,it is rounded off to n + 1 decimal place.


round

protected java.lang.String round
Round mode.

Constructor Detail

DecimalTag

public DecimalTag()
Method Detail

getId

public java.lang.String getId()
Fetches the name of scripting variable.

Overrides:
getId in class javax.servlet.jsp.tagext.TagSupport
Returns:
Scripting variable

setId

public void setId(java.lang.String id)
Sets the name of scripting variable.

Overrides:
setId in class javax.servlet.jsp.tagext.TagSupport
Parameters:
id - Name of scripting variable

getFilter

public boolean getFilter()
Get filter method to decide whether the special HTML characters are to be filtered.

Returns:
When the special HTML characters are to be filtered, it is true
.

setFilter

public void setFilter(boolean filter)
setFilter method to decide whether the special HTML characters are to be filtered.

Parameters:
filter - When the special HTML characters are to be filtered, it is true

getIgnore

public boolean getIgnore()
Get ignore method to decide whether to ignore when bean is not found.

Returns:
When it is to be ignored, it is true

setIgnore

public void setIgnore(boolean ignore)
SetIgnore method to decide whether to ignore when bean is not found.

Parameters:
ignore - When it is to be ignored, it is true

getName

public java.lang.String getName()
Fetches the name of bean that includes the data to be formatted.

Returns:
bean name

setName

public void setName(java.lang.String name)
Sets the name of bean that includes the data to be formatted.

Parameters:
name - bean name

getProperty

public java.lang.String getProperty()
Fetches the name of property which is accessed in the specified bean.

Returns:
Name of property whic is accessed in the specified bean.

setProperty

public void setProperty(java.lang.String property)
Sets the name of property which is accessed in the specified bean.

Parameters:
property - Name of property which is accessed in the specified bean.

getScope

public java.lang.String getScope()
Fetches the scope to search the specified bean.

Returns:
Scope

setScope

public void setScope(java.lang.String scope)
Sets the scope to search the specified bean.

Parameters:
scope - Scope to search the specified bean.

getPattern

public java.lang.String getPattern()
Fetches the pattern that specifies the output format.

Returns:
Pattern that specifies the output format.

setPattern

public void setPattern(java.lang.String pattern)
Sest the pattern that specifies the output format.

Parameters:
pattern - Pattern

getValue

public java.lang.String getValue()
Fetches the value to be formatted.

Returns:
Value to be formatted

setValue

public void setValue(java.lang.String value)
Sets the value to be formatted.

Parameters:
value - Value to be formatted

getScale

public int getScale()
Fetches the number of decimal places after rounding off.

Returns:
Number of decimal places

setScale

public void setScale(int scale)
Sets the number of decimal places after rounding off.

Parameters:
scale - Number od decimal places

getRound

public java.lang.String getRound()
Fetches the round mode.

Returns:
Round mode

setRound

public void setRound(java.lang.String round)
Sets the round mode.

Parameters:
round - Round mode

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Method which is called at the time of starting tag evaluation.

Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.TagSupport
Returns:
Process control instructions. It is always SKIP_BODY
Throws:
javax.servlet.jsp.JspException - JSP exception

release

public void release()
Releases all allocated resources.

Specified by:
release in interface javax.servlet.jsp.tagext.Tag
Overrides:
release in class javax.servlet.jsp.tagext.TagSupport