0

I originally wrote a desktop application that uses JasperReports.

In this application the user can dynamically change the locale setting and this change will be reflected in the reports. This works fine.

I have a web application that has the same functionality. Everything works fine except for the currency symbol where I get a ¤ instead of the symbol. The date is formatted properly according to the locale and so are the number formats. The only problem is the currency symbol. I do not have this problem in the desktop application even though I am using the exact same jrxml file to generate the reports in both cases. So the problem cannot be from the jrxml file. Does anyone know how to solve this problem?

UPDATE: Ok, if I use the command

myLocale = Locale.CANADA;

and then I pass the myLocale variable to the jasper report everything works fine, but since my web application allows the user to choose whichever locale he/she wants I create a loop the following way:

Locale myLocale = Locale.getDefault();
Locale[] locales = Locale.getAvailableLocales();
int localeCount = locales.length;
for (int i = 0; i < localeCount; i++) {
    if (locales[i].getDisplayName().equals(##Whatever the user chose##)) 
        myLocale = locales[i];
}

In this case when I pass the variable myLocale to the jasper report I get the above mentioned problem with the currency symbol (but not with number formats and dates). Can someone point out what is wrong with the above code? Thanks.

user3245747
  • 805
  • 2
  • 17
  • 30

1 Answers1

0

I have found the solution to the problem. Apparently i needed to drop from the list of locales those that do not satisfy the following condition: myLocale.get(j).getCountry().length() > 0. The code now becomes:

Locale[] locales = Calendar.getAvailableLocales();
//Convert to list in order to remove some elements
List<Locale> locales2 = new ArrayList<Locale>(Arrays.asList(locales));
int localeCount = locales2.size();
for (int j = 0; j < localeCount; j++) {
    if (!(locales2.get(j).getCountry().length() > 0)) {
        locales2.remove(j);
        localeCount--;
    }
}
//Now loop over the list in search for the selected locale
for (int i = 0; i < localeCount; i++) {
    if (locales2.get(i).getDisplayName().equals(**whatever the user chose**)) {
        myLocale = locales2.get(i);
        break;
    }
}

Now the currency symbol appears properly.

user3245747
  • 805
  • 2
  • 17
  • 30