Andres Gonzalez
Andres Gonzalez

Reputation: 63

fmt formatNumber type="currency" shows "¤" instead of actual currency symbol

I have the following code to show an amount as currency:

<fmt:formatNumber type="currency" value="${camp.montoTotal}"/>

When I run the application in Eclipse (actually I am using STS), it looks good: "$500". But when I deploy the WAR file to the server (using Tomcat8 on Ubuntu LTS 14.04), it shows "¤500", i.e., shows the generic currency marker instead of the actual sign. I tried to force the locale with:

<META http-equiv="Content-Language" content="es-AR">
<fmt:setLocale value="es-AR"/>

but with the same result. Why can it be?

Upvotes: 3

Views: 2501

Answers (2)

Ivan Lynch
Ivan Lynch

Reputation: 562

first, you need to import the tag library:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

next, set the country with setLocale

<fmt:setLocale value="es-AR"/>

then you can format the number with formatNumber tag

<fmt:formatNumber value="${camp.montoTotal}" type="currency" currencySymbol="$"/>

in the attribute you can add the currencySymbol that you want to use.

Hope it helps you. Regards,

Upvotes: 1

Andres Gonzalez
Andres Gonzalez

Reputation: 63

I finally found the answer!!

Originally I had the messageSource bean configured in the app-config xml. When I moved it to the applicationContext xml, the problem was solved. I had to do this because I also had problems when trying to access message properties in the controller with getMessage function.

  <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
       <property name="basename" value="messages"/>
  </bean>

Conclusion: messageSource must be configured in the application context, not in the root configuration xml.

Upvotes: 1

Related Questions