Package org.apache.struts2.components
Class Number
java.lang.Object
org.apache.struts2.components.Component
org.apache.struts2.components.ContextBean
org.apache.struts2.components.Number
Format Number object in different ways.
The number tag will allow you to format a Number in a quick and easy way, based on the java.text.NumberFormat class. There are four basic number types, a number, a currency, a percentage and an integer. If a currency is specified, the number format will match the given currency. Further parameters can be overridden as needed.
If a type is not defined, it will finally fall back to the default NumberFormat.getNumberInstance() formatting.
Note: If the requested Number object isn't found on the stack, a blank will be returned.
Configurable attributes are:
- name
- currency - you can specify your own currency or as an OGNL expression
- type - if not specified try to find base on struts.number.format property
- groupingUsed - see NumberFormat.isGroupingUsed
- maximumFractionDigits - see NumberFormat.setMaximumFractionDigits
- maximumIntegerDigits - see NumberFormat.setMaximumIntegerDigits
- minimumFractionDigits - see NumberFormat.setMinimumFractionDigits
- minimumIntegerDigits - see NumberFormat.setMinimumIntegerDigits
- parseIntegerOnly - see NumberFormat.isParseIntegerOnly
- roundingMode - see below
Possible values for rounding mode are:
- ceiling
- down
- floor
- half-down
- half-even
- half-up
- unnecessary
- up
Examples
<!-- START SNIPPET: example --> <s:number name="invoice.total" type="currency" currency="XYZ" /> <s:number name="invoice.quantity" type="number" /> <s:number name="invoice.discount" type="percentage" /> <s:number name="invoice.terms" type="integer" /> <!-- END SNIPPET: example -->
Number
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property name to fall back when no format is specifiedFields inherited from class org.apache.struts2.components.ContextBean
var
Fields inherited from class org.apache.struts2.components.Component
actionMapper, attributes, COMPONENT_STACK, devMode, escapeHtmlBody, performClearTagStateForTagPoolingServers, stack, standardAttributesMap, throwExceptionOnELFailure
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Callback for the end tag of this component.getName()
getType()
void
setCurrency
(String currency) void
setGroupingUsed
(Boolean groupingUsed) void
setMaximumFractionDigits
(Integer maximumFractionDigits) void
setMaximumIntegerDigits
(Integer maximumIntegerDigits) void
setMinimumFractionDigits
(Integer minimumFractionDigits) void
setMinimumIntegerDigits
(Integer minimumIntegerDigits) void
void
setParseIntegerOnly
(Boolean parseIntegerOnly) void
setRoundingMode
(String roundingMode) void
Methods inherited from class org.apache.struts2.components.ContextBean
getVar, putInContext, setVar
Methods inherited from class org.apache.struts2.components.Component
addAllAttributes, addParameter, completeExpression, copyAttributes, determineActionURL, determineNamespace, end, escapeHtmlBody, fieldError, findAncestor, findString, findString, findValue, findValue, findValue, getAttributes, getComponentStack, getNamespace, getPerformClearTagStateForTagPoolingServers, getStack, getStandardAttributes, isAcceptableExpression, isValidTagAttribute, popComponentStack, setActionMapper, setDevMode, setEscapeHtmlBody, setNotExcludedAcceptedPatterns, setPerformClearTagStateForTagPoolingServers, setThrowExceptionsOnELFailure, setUrlHelper, start, stripExpression, toString, usesBody
-
Field Details
-
NUMBERTAG_PROPERTY
Property name to fall back when no format is specified- See Also:
-
-
Constructor Details
-
Number
-
-
Method Details
-
end
Description copied from class:Component
Callback for the end tag of this component. Should the body be evaluated again?
NOTE: will pop component stack. -
setType
-
setCurrency
-
getName
- Returns:
- Returns the name.
-
setName
-
getType
- Returns:
- Returns the format.
-
getCurrency
- Returns:
- Returns the currency.
-
setGroupingUsed
-
isGroupingUsed
- Returns:
- Returns the grouping used.
-
getMaximumFractionDigits
- Returns:
- the maximumFractionDigits
-
setMaximumFractionDigits
- Parameters:
maximumFractionDigits
- the maximumFractionDigits to set
-
getMaximumIntegerDigits
- Returns:
- the maximumIntegerDigits
-
setMaximumIntegerDigits
- Parameters:
maximumIntegerDigits
- the maximumIntegerDigits to set
-
getMinimumFractionDigits
- Returns:
- the minimumFractionDigits
-
setMinimumFractionDigits
- Parameters:
minimumFractionDigits
- the minimumFractionDigits to set
-
getMinimumIntegerDigits
- Returns:
- the minimumIntegerDigits
-
setMinimumIntegerDigits
- Parameters:
minimumIntegerDigits
- the minimumIntegerDigits to set
-
isParseIntegerOnly
- Returns:
- the parseIntegerOnly
-
setParseIntegerOnly
- Parameters:
parseIntegerOnly
- the parseIntegerOnly to set
-
getRoundingMode
- Returns:
- the roundingMode
-
setRoundingMode
- Parameters:
roundingMode
- the roundingMode to set
-