6

Background

We have an org that has advanced multi-currency activated. Since this feature is activated we are not enabled to use apex:inputField on currency fields. Instead of this we are using apex:inputText

If advanced currency management is enabled, you can't bind Visualforce pages that use <apex:inputField> or <apex:outputField> components to currency fields that support advanced currency management.

The change of apex:inputField by apex:inputText to edit currency field works fine.

In addition, We also have multi-locale users.

Problem

When the field is been showing for editing the decimal symbol showed is a dot (When the locale symbol for that should be comma).

enter image description here

But, when the user try to edit this field and insert a number using comma as decimal separator a conversion error occurs.

enter image description here

Failed attempts so far

We've tried to replace using javascript the comma by dot onsubmit. But this symbols should depends of user's locale.

Later, we've tried by using apex:input type=number but is not possible to join the field to that component.

Also, we have tried to replace the save method on the controller, and convert there the text to number, but the same error was showed.

Query

Is there any standard solution to manage currency fields using an inputText? Can I force the format of inputText ?

Thx for your time.

3 Answers 3

1

The doc may be contradictory as I use apex:inputField with ACM all day, every day. From the VF standard component reference:

You can't associate this inputField with a formula merge field of type currency if your organization is using dated exchange rates.

This is saying you can't do this: value="{!IF(foo__c,opportunity.amount,opportunity.next_best_amount__c)}"

but you can certainly do <apex:inputField value="{!opportunity.amount}"/> as my VF pages do that (actually they do : <apex:inputField value="{!ow.o.amount}"/> referring to a wrapper class around Opportunity but that shouldn't matter.

Now outputFields are a different story and here the VF doc is consistent with your ACM doc snippet:

You cannot associate this output field with a currency merge field if that field value is calculated using dated exchange rates.

I would go with a component and its own controller that could deal with the locale issues. Pass in the currency field to the component and let the component's controller format it for you.

1
  • You are right. I fell into the wrong doc trap. The outputField works fine using a outputText Commented Mar 12, 2014 at 7:20
0

In the save method in the controller you could replace the comma with a decimal.

price.replace(',','.');

In the get method you could do the reverse to put the comma in for display.

Instead of:

String price{get;set;}

Define the get method and replace the decimal

public String getPrice(){
    return price.replace('.',',');
}
0

Not sure Whether @Stephen's answer will work for muli-local. Check the following link also https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript

1
  • Thank you Rob, but the browser locale is not always the Salesforce user local and that will give me an issue Commented Mar 11, 2014 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .