deklotz Posted February 5, 2007 Share Posted February 5, 2007 Greetings. Another Locale question. What I want: 1) Numbers formated to the passed Locale parameter 2) Percents placed according to the passed Locale parameter. What I have: 1) Client applet, server tomcat jdk 1.5, Jasper 1.3.02) client Locale serialized to server3) (as an example) Jasper REPORT_LOCALE set to "nl_nl"4) Local server JVM set to default US Locale5) Jasper invoked on server to create PDF6) JRXML file with several Text Field Expressions such as: Double with pattern #,##0.00 % String with the Expression : msg("{0,number,percent}", new Double [] { $V{CL11_V_Z} }) What I get: 1) It appears that I get the default US Locale.2) Numbers have US commas and decimal.3) Percents are not correct. I hope someone can point me to what I'm doing wrong. Do I need a resource bundle even though I'm not using that aspect of it?Do I need to have a different Expression in order to have the passed REPORT_LOCALE used?Is the "nl_nl" incorrect? I've noticed that sometimes the denmark Locale is marked nl_NL. Thank you in advance for any ideas. -Dennis Here is a section from the jrxml file:Code:<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Opaque" x="257" y="2" width="26" height="12" forecolor="#000000" backcolor="#FFFFFF" key="textField-37"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Center" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="6" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[msg("{0,number,###.##}", new Double[] { $F{COLUMN_7}})]]></textFieldExpression></textField> and another section: Code:[code]<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement mode="Opaque" x="414" y="16" width="45" height="18" forecolor="#0033CC" backcolor="#FFFFFF" key="textField-49"/> <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <textElement textAlignment="Center" verticalAlignment="Top" rotation="None" lineSpacing="Single"> <font fontName="Arial" pdfFontName="Helvetica" size="6" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" /> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[(($V{CL11_V_Z}.doubleValue() <= 0.0) ? " " : (($V{CL11_V_Z}.doubleValue() < 0.0001) ? "<" + (msg("{0,number,percent}", new Double[] { new Double(0.0001) })) : (msg("{0,number,percent}", new Double [] { $V{CL11_V_Z} }))))]]></textFieldExpression></textField> Post edited by: deklotz, at: 2007/02/05 14:44 Post edited by: deklotz, at: 2007/02/05 14:45Post edited by: deklotz, at: 2007/02/05 17:43 Link to comment Share on other sites More sharing options...
deklotz Posted February 5, 2007 Author Share Posted February 5, 2007 Aye I am wondering if I need to hit the books again... I just verified that inside of the class JREvaluator the method getMessageFormat is indeed receiving the Locale "nl_nl". Code:/** * */private MessageFormat getMessageFormat(String pattern){ MessageFormat messageFormat = new MessageFormat(""«»); messageFormat.setLocale((Locale)locale.getValue()); messageFormat.applyPattern(pattern); return messageFormat;} The pattern is "{0,number,###.##}" and locale "nl_nl" yet the resulting number is 47.09! Am I misunderstanding how the pattern is used? How do I specify a pattern that will use , for a . in the right locale? Thanks again for taking the time to respond. Link to comment Share on other sites More sharing options...
deklotz Posted February 6, 2007 Author Share Posted February 6, 2007 Just in case this turns out useful for someone else.... Turns out that "nl_nl" is wrong. I am using an Applet with plain old java objects being serialized to the server. In order to set the Locale for the session (back on the server) I am setting accept-language. At first I used Locale.getDefault().toString() which created the string "nl_nl". This is wrong. I must use Locale.getDefault().getLanguage () instead. Now I end up with just "nl". Now when I'm down inside the server, tomcat (for free) takes the accept-language if it is present and modifies the request object to have the correct Locale object. This I then later use as a parameter for Jasper and now the msg() expression work. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now