[
https://issues.apache.org/jira/browse/TRINIDAD-1374?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12668616#action_12668616
]
Cale Scholl commented on TRINIDAD-1374:
---------------------------------------
According to the comments in
trinidad-api\src\main\xrts\org\apache\myfaces\trinidad\resource\MessageBundle.xrts,
the substitution parameters are supposed to be:
{0} the label that identifies the component
{1} value entered by the user
Thus, getAsObject() now does:
if (typeIdx == _PATTERN_TYPE)
{
// We call this since the pattern may contain the generic currency sign
'¤', which we don't
// want to display to the user.
pattern = getLocalizedPattern(context, pattern, dfs);
params = new Object[] {label, value, pattern};
}
else if (typeIdx == _NUMBER_TYPE)
{
params = new Object[] {label, value};
}
else if (typeIdx == _CURRENCY_TYPE)
{
params = new Object[] {label, value, fmt.format(_EXAMPLE_CURRENCY)};
}
else if (typeIdx == _PERCENT_TYPE)
{
params = new Object[] {label, value, fmt.format(_EXAMPLE_PERCENT)};
}
Furthermore, this patch addresses another issue. If the pattern is obtained
programmatically, as in:
DecimalFormat numberFormat =
(DecimalFormat)DecimalFormat.getCurrencyInstance(mLocale);
mCurrencyPattern = numberFormat.toPattern();
then the pattern contains the currency sign '¤'. The currency sign '¤' is just
a generic placeholder for all locales, which is supposed to tell the user
"replace this with the actual currency symbol for your locale". But seeing this
currency sign in a converter error message is confusing; therefore, the
following method was added:
/**
* If <code>pattern</code> contains the generic currency sign '¤', this
method will replace it
* with the localized currency symbol (if one exists).
* @param context the FacesContext
* @param pattern the pattern to be localized
* @param dfs the DecimalFormatSymbols; if null, will be constructed from the
<code>context</code>
* @return
*/
public String getLocalizedPattern(FacesContext context, String pattern,
DecimalFormatSymbols dfs)
{
if (pattern == null)
return null;
// If the pattern contains the generic currency sign '¤', replace it with
the localized
// currency symbol (if one exists), so that when the pattern is displayed
(such as in an error
// message), it is more meaningful to the user.
// If the pattern contains '¤¤', replace it with the international currency
symbol.
// For an explanation of this behavior, see section "Special Pattern
Characters" at:
// http://java.sun.com/javase/6/docs/api/java/text/DecimalFormat.html
// The unicode for '¤' is: \u00A4
// The xml hex is : ¤
int idx = pattern.indexOf("¤");
if (idx == -1)
return pattern;
if (dfs == null)
{
String type = getType();
RequestContext reqCtx = RequestContext.getCurrentInstance();
Locale locale = _getLocale(reqCtx, context);
NumberFormat fmt = _getNumberFormat(pattern, type, locale, reqCtx);
DecimalFormat df = (DecimalFormat) fmt;
dfs = df.getDecimalFormatSymbols();
}
if (idx + 1 < pattern.length() && pattern.charAt(idx + 1) == '¤')
{
// Matcher.quoteReplacement ensures that the replacement string is
properly escaped.
String symbol = dfs.getInternationalCurrencySymbol();
if (symbol.length() > 0)
pattern = pattern.replaceFirst("¤¤", Matcher.quoteReplacement(symbol));
}
else
{
// Matcher.quoteReplacement ensures that the replacement string is
properly escaped.
String symbol = dfs.getCurrencySymbol();
if (symbol.length() > 0)
pattern = pattern.replaceFirst("¤", Matcher.quoteReplacement(symbol));
}
return pattern;
}
> NumberConverter with type='number' and pattern set gives malformed error
> ------------------------------------------------------------------------
>
> Key: TRINIDAD-1374
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1374
> Project: MyFaces Trinidad
> Issue Type: Bug
> Components: Components
> Reporter: Yee-Wah Lee
> Priority: Minor
>
> 1. Add an inputText with child numberConverter that has type='number' and a
> pattern set.
> e.g.
> <tr:inputText value="99.99" label="number converter1">
> <f:facet name="help">
> <tr:outputText value="type='number' integerOnly='true' -
> This will result in fraction part to be omitted"/>
> </f:facet>
> <f:convertNumber type="number" pattern="0.0"/>
> </tr:inputText>
> 2. Run the jspx and type in malformed input.
> 3. submit the page, the error message for the component is:
> The format of the number must match this pattern: {2}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.