You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Lipscombe <ad...@expensys.com> on 2007/02/01 12:51:38 UTC

Is it possible to paramterize calls to form bean getters?

Folks


I need to internationalize an app - returning Locale specific formats for currency and date.

One way to do that is to add getLocalised<PropertyName>() and setLocalised<PropertyName>() to the 
formbeans for each affected property. These methods will then apply whatever formatting is needed.

But, for the <bean:write> tag to work this involves having an extra getter/setter for each property 
that needs localisation.


Is there anyway round this? Is there an accepted solution?


TIA - Adam



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


Re: Is it possible to paramterize calls to form bean getters?

Posted by Adam Lipscombe <ad...@expensys.com>.
OK thanks.

This was my original approach, except now I am having trouble with the bean:write + formatKey 
approach - please see my other post entitled "formatting money values with bean:write".

So summarise:
It seems that whenever the formatKey specification results in a lookup of a format String that does 
not match the  client-side the formatting fails with the stack trace below.

eg:
The default format String is "#,##0.00".
The client side locale is Portugal (currency format = "#.#00,00")
There is no specific property bundle for Portugal - so the default format String should be used.

However the formatting fails with the stack trace below.
I have looked at WriteTag.java (Struts 1.1) and to be honest I cannot see how it can work.
A format String is always found because the PropetyMessageResources class first tries to find a 
locale specific resource, then returns the default locale resource (which is always present).

However, and this is the nub of the question I believe,  because a formatString has been found, 
WriteTag.java then calls "( ( DecimalFormat ) format ).applyLocalizedPattern( formatString );".

My understanding is hat the param passed to "applyLocalizedPattern()" must match the required 
pattern for the locale that the DecimalFormat  instance was constructed with?

If my assumption is correct then the default format string will very often be wrong, and cause the 
exception.

Basically, AFAICS the applyLocalizedPattern(formatString) will always be called because the resource 
lookup always succeeds if the resource is present at all (i.e. not specifically for the client-side 
locale). The applyLocalizedPattern(formatString) will then fail if the pattern does not match that 
required by the locale.



Or am I missing something?  Surely I must be :-)
Any help totally appreciated....


Thanks in advance - Adam



Stack Trace:

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:
> Adam Lipscombe wrote:
>> Folks
>>
>> I need to internationalize an app - returning Locale specific formats 
>> for currency and date.
>>
>> One way to do that is to add getLocalised<PropertyName>() and 
>> setLocalised<PropertyName>() to the formbeans for each affected 
>> property. These methods will then apply whatever formatting is needed.
> 
> Ugh, you'd have to have a seperate getter/setter pair for every locale 
> you wanted to support, and how would you know which one to call in the JSP?
> 
>> But, for the <bean:write> tag to work this involves having an extra 
>> getter/setter for each property that needs localisation.
>>
>> Is there anyway round this? Is there an accepted solution?
> 
> Your getters/setters shouldn't need to know about the locale, they just 
> make the data available. Formatting for locale should happen in the 
> view. Format strings go in your per-locale resource bundle, and are 
> referenced with the formatKey attribute of the bean:write tag [1].
> 
> There are other ways to do the same thing (including using the JSTL 
> 'fmt' tags/functions instead of bean:write), but the objective is the 
> same: make formatting data part of your localization resources.
> 
> L.
> 
> [1] http://struts.apache.org/1.x/struts-taglib/tlddoc/bean/write.html
> 
> 
> ---------------------------------------------------------------------
> 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: Is it possible to paramterize calls to form bean getters?

Posted by Laurie Harper <la...@holoweb.net>.
Adam Lipscombe wrote:
> Folks
> 
> I need to internationalize an app - returning Locale specific formats 
> for currency and date.
> 
> One way to do that is to add getLocalised<PropertyName>() and 
> setLocalised<PropertyName>() to the formbeans for each affected 
> property. These methods will then apply whatever formatting is needed.

Ugh, you'd have to have a seperate getter/setter pair for every locale 
you wanted to support, and how would you know which one to call in the JSP?

> But, for the <bean:write> tag to work this involves having an extra 
> getter/setter for each property that needs localisation.
> 
> Is there anyway round this? Is there an accepted solution?

Your getters/setters shouldn't need to know about the locale, they just 
make the data available. Formatting for locale should happen in the 
view. Format strings go in your per-locale resource bundle, and are 
referenced with the formatKey attribute of the bean:write tag [1].

There are other ways to do the same thing (including using the JSTL 
'fmt' tags/functions instead of bean:write), but the objective is the 
same: make formatting data part of your localization resources.

L.

[1] http://struts.apache.org/1.x/struts-taglib/tlddoc/bean/write.html


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