You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurie Harper <la...@holoweb.net> on 2007/02/01 03:12:27 UTC

Re: formatting money values with bean:write

Adam Lipscombe wrote:
> Folks
> 
> 
> I am using "<bean:write name="myBean" property="myBeanProperty" 
> formatKey="global.moneyFormat"/>
> 
> global.moneyFormat is defined in the vanilla 
> ApplicationResources.properties file as "#,##0.00"
> 
> To support users in France and Germany there are also 
> ApplicationResources_fr and ApplicationResources_de property files. 
> These define the moneyFormat as "# ##0,00" and "#.##0,00". This all 
> works fine.
> 
> 
> But, when a user accesses the system from a client whose locale uses a 
> non-USA/UK style currency format string and the locale is NOT France or 
> Germany (e.g. "#.##0,00" - Portugal or Brazil) the system fails with 
> "javax.servlet.ServletException: Wrong format string: '#,##0.00'"
> 
> 
> I think what is happening is that the system is using the default 
> "global.moneyFormat" property String from the vanilla 
> ApplicationResources file (which is what I would expect).
> But when this default pattern is applied it does not match the one 
> expected by the client-side locale and so the pattern application fails.
> 
> 
> What I thought was supposed to happen was that if an appropriate 
> ApplicationResources_XX.properties file could not be found the 
> "global.moneyFormat" property from the vanilla properties file would be 
> used and simply applied?
> 
> 
> Does anyone know what is supposed to happen?
> Is it necessary to have a separate ApplicationResources_XX props file 
> for every locale that might access the system? Surely not?
> 
> 
> TIA - Adam

No, it should work as you expect. What's the full stack trace (including 
root cause)?

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: formatting money values with bean:write

Posted by Adam Lipscombe <ad...@expensys.com>.
Further to this I have delved into WriteTag.java, and see the following code in formatValue():


// Try to retrieve format string from resources by the key from formatKey.
if( ( formatString==null ) && ( formatKey!=null ) ) {
   formatString = retrieveFormatString( this.formatKey );
   if( formatString!=null )
     formatStrFromResources = true;
}

// Prepare format object for numeric values.
if ( value instanceof Number ) {

   if( formatString==null ) {
     if( ( value instanceof Byte )    ||
         ( value instanceof Short )   ||
         ( value instanceof Integer ) ||
         ( value instanceof Long )    ||
         ( value instanceof BigInteger ) )
       formatString = retrieveFormatString( INT_FORMAT_KEY );
     else if( ( value instanceof Float ) ||
              ( value instanceof Double ) ||
              ( value instanceof BigDecimal ) )
       formatString = retrieveFormatString( FLOAT_FORMAT_KEY );
       if( formatString!=null )
        formatStrFromResources = true;
}


if( formatString!=null ) {
   try {
     format = NumberFormat.getNumberInstance( locale );
     if( formatStrFromResources )
       ( ( DecimalFormat ) format ).applyLocalizedPattern( formatString );
     else
       ( ( DecimalFormat ) format ).applyPattern( formatString ); 

   } catch( IllegalArgumentException _e ) {
     JspException e = new JspException(messages.getMessage("write.format", formatString));
     RequestUtils.saveException(pageContext, e);
     throw e;
   }


The formatStrFromResources String is set true if the formatString was successfuly obtained from the 
resources list. It then calls applyLocalizedPattern(), passing the format String that was obtained 
from the resources.

But AFAICS, if the formatString obtained from the app resources bundle is NOT appropriate for the 
locale then the call to applyLocalizedPattern() will fail.
And indeed in my test case the formatString is not appropriate for the locale - it is the default 
formatString that is retrieved no specific resource for the locale is found.


So, it seems to me that the above code must always fail if the formatString is present at all in 
resources bundle.
To make it work the retrieveFormatString() must return null if the formatString is not defined FOR 
THE LOCALE.


Or am I missing something fundamental?

Any insight gratefully receieved - this is driving me nuts.


TIA - Adam











Adam Lipscombe wrote:
> Thanks for this.
> 
> The stack trace is below.  The global.moneyFormat property is defined in 
> the app resources file as #,##0.00. The client had a Portuguese locale 
> set, which I believe has a currency format of #.##0,00.
> 
> As you say, I would expect the system to look for a resources file that 
> is specific to the Portuguese locale, and it cannot find one, revert to 
> standard.
> 
> 
> Any ideas?
> 
> 
> 
> Thanks - Adam
> 
> 
> 
> 
> 
> ApplicationDispatcher[/ExpenSysWT]: Servlet.service() for servlet 
> debugjsp threw exception
> javax.servlet.jsp.JspException: Wrong format string: '#,##0.00'
>     at 
> org.apache.struts.taglib.bean.WriteTag.formatValue(WriteTag.java:376)
>     at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:292)
>     at 
> org.apache.jsp.pages.pec.Pec_jsp._jspx_meth_bean_write_26(Pec_jsp.java:6518) 
> 
>     at org.apache.jsp.pages.pec.Pec_jsp._jspService(Pec_jsp.java:3746)
>     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>     at 
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) 
> 
>     at 
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
>     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) 
> 
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) 
> 
>     at 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704) 
> 
>     at 
> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474) 
> 
>     at 
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409) 
> 
>     at 
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) 
> 
>     at 
> org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069) 
> 
>     at 
> org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455) 
> 
>     at 
> org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279) 
> 
>     at 
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
>     at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) 
> 
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) 
> 
>     at 
> com.expensys.expensyswt.struts.filters.TimeoutFilter.doFilter(TimeoutFilter.java:184) 
> 
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186) 
> 
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) 
> 
>     at 
> com.expensys.expensyswt.struts.filters.AvailabilityFilter.doFilter(AvailabilityFilter.java:130) 
> 
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186) 
> 
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) 
> 
>     at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) 
> 
>     at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) 
> 
>     at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at 
> org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) 
> 
>     at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) 
> 
>     at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) 
> 
>     at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) 
> 
>     at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) 
> 
>     at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 
> 
>     at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) 
> 
>     at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
> 
>     at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) 
> 
>     at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
>     at 
> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
>     at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
>     at 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) 
> 
>     at 
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
>     at 
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) 
> 
>     at java.lang.Thread.run(Thread.java:534)
> 
> 
> 
> Laurie Harper wrote:
>>
>> No, it should work as you expect. What's the full stack trace 
>> (including root cause)?
>>
>> L.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 

________________________________
Adam Lipscombe
Escalus Software Systems
adam.lipscombe@expensys.com
Tel: 08450 170 850
www.expensys.com

This email and any files transmitted with it, including replies and
forwarded copies, may contain privileged and confidential information and
is intended solely for the person or organisation to whom it is addressed.
If you have received this communication in error, please notify us by email
(Notices@Escalus.net) or telephone (+44 (0)8450 170 850) and then delete the
email and any copies of it. Views or opinions expressed by an individual
within this email may not necessarily reflect the views of Escalus Software
Systems Ltd.

Although most emails and attachments from Escalus Software Systems Ltd are
screened, it is the responsibility of the recipient to ensure
that they are virus free. Escalus Software Systems Ltd will not accept any
liability for damage caused by a virus.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: formatting money values with bean:write

Posted by Adam Lipscombe <ad...@expensys.com>.
Thanks for this.

The stack trace is below.  The global.moneyFormat property is defined in the app resources file as 
#,##0.00. The client had a Portuguese locale set, which I believe has a currency format of #.##0,00.

As you say, I would expect the system to look for a resources file that is specific to the 
Portuguese locale, and it cannot find one, revert to standard.


Any ideas?



Thanks - Adam





ApplicationDispatcher[/ExpenSysWT]: Servlet.service() for servlet debugjsp threw exception
javax.servlet.jsp.JspException: Wrong format string: '#,##0.00'
	at org.apache.struts.taglib.bean.WriteTag.formatValue(WriteTag.java:376)
	at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:292)
	at org.apache.jsp.pages.pec.Pec_jsp._jspx_meth_bean_write_26(Pec_jsp.java:6518)
	at org.apache.jsp.pages.pec.Pec_jsp._jspService(Pec_jsp.java:3746)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
	at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
	at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at com.expensys.expensyswt.struts.filters.TimeoutFilter.doFilter(TimeoutFilter.java:184)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at com.expensys.expensyswt.struts.filters.AvailabilityFilter.doFilter(AvailabilityFilter.java:130)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
	at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
	at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
	at java.lang.Thread.run(Thread.java:534)



Laurie Harper wrote:
> 
> No, it should work as you expect. What's the full stack trace (including 
> root cause)?
> 
> L.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org