Hi Elisabeth,

I have found the problem.

In convertToObject, before returning, just trim the string as follows:

  Object o = super.convertToObject(newString.trim(), previousValue);
  return o;

The French locale puts a blank char in currency format which was not
acceptable to the DecimalFomat's parse method.

Please see the attached ULC snippet and also a Swing snippet.

I am not sure why it worked in 6.0.4. It should have had the same problem.

I hope this helps.

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Kliman, Elizabeth
Sent: Tuesday, September 05, 2006 7:45 PM
To: [EMAIL PROTECTED] Com
Subject: RE: [ULC-developer] ULC 6.1 Currency extension and Locale


Janak,
Yes, it worked perfectly in 6.0.4, which is why I'm so concerned about this.
But perhaps I've got something mixed up after the conversion.
Here is the UICurrencyAmountDataType.java class:
package ca.fcc.ulc.client;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;
import com.ulcjava.base.client.datatype.DataTypeConversionException;
import com.ulcjava.base.client.datatype.UINumberDataType;
public class UICurrencyAmountDataType extends UINumberDataType {
        private static String DOLLARSIGN = "$";
        private NumberFormat currencyFormat;
        private String currencySymbol;
        private String language;
        private String country;
        public UICurrencyAmountDataType() {
                super();
        }
        protected void postInitializeState() {
                super.postInitializeState();
                Locale locale = new Locale(language, country);
                currencyFormat = NumberFormat.getCurrencyInstance(locale);
                DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
                currencySymbol = dfs.getCurrencySymbol();
                StringBuffer buf = new StringBuffer();
                if (fValidChars != null) {
                        for (int i = 0; i < fValidChars.length(); i++) {
                                if (fValidChars.charAt(i) != 'E') {
                                        buf.append(fValidChars.charAt(i));
                                }
                        }
                }
                buf.append(currencySymbol);
                buf.append(')');
                buf.append('(');
                fValidChars = buf.toString();
        }
        public Object convertToObject(String aNewString, Object
aPreviousValue) throws DataTypeConversionException {
                if (!currencySymbol.equals(DOLLARSIGN)) { return
super.convertToObject(aNewString, aPreviousValue); }
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < aNewString.length(); i++) {
                        if (aNewString.charAt(i) == '(') {
                                sb.append('-');
                        }
                        if (currencySymbol.indexOf(aNewString.charAt(i))
== -1 && aNewString.charAt(i) != ')' && aNewString.charAt(i) != '(') {
                                sb.append(aNewString.charAt(i));
                        }
                }
                if (sb.length() == 1 && sb.charAt(0) == '-')
                        aNewString = null;
                else
                        aNewString = sb.toString();
                Object o = super.convertToObject(aNewString,
aPreviousValue);
                return o;
        }
        public String convertToString(Object anObject, boolean aForEditing)
{
                if (!currencySymbol.equals(DOLLARSIGN)) { return
super.convertToString(anObject, aForEditing); }
                String s = super.convertToString(anObject, aForEditing);
                String cs = s;
                if (s.length() != 0) {
                        try {
                                cs =
currencyFormat.format(fConverter.convertToObject(s));
                        }
                        catch (DataTypeConversionException e) {
                                e.printStackTrace();
                        }
                }
                return cs;
        }
        public void setLanguage(String aLanguage) {
                language = aLanguage;
        }
        public void setCountry(String aCountry) {
                country = aCountry;
        }
}
And here is the ULCCurrencyAmountDataType.java:
package ca.fcc.ulc.application.datatype;
import java.util.Locale;
import ca.fcc.lang.UserEnvironment;
import com.ulcjava.base.application.datatype.ULCNumberDataType;
public class ULCCurrencyDataType extends ULCNumberDataType {
        private static final String COUNTRY = "country";
        private static final String LANGUAGE = "language";
        protected String typeString() {
                return "ca.fcc.ulc.client.UICurrencyAmountDataType";
        }
        public ULCCurrencyDataType() {
                super(UserEnvironment.getUserEnvironment().getLocale());
                setInteger(false);
                setMinFractionDigits(2);
                setMaxFractionDigits(2);
        }
        protected void uploadStateUI() {
                super.uploadStateUI();
                Locale locale =
UserEnvironment.getUserEnvironment().getLocale();
                setStateUI(LANGUAGE, null, locale.getLanguage());
                setStateUI(COUNTRY, null, locale.getCountry());
        }
}
Any help would be appreciated.  Thanks!
Elizabeth Kliman, B.Sc., SCJP
Developer / Développeur
Information Technology / Technologie de l'information
Farm Credit Canada / Financement agricole Canada
1800 Hamilton Street, P.O. Box 4320
1800, rue Hamilton, C.P. 4320
Regina SK S4P 4L3
Tel/Tél. : (306) 780-3382 Fax/Télec. : (306) 780-5655
E-mail/Courriel : [EMAIL PROTECTED]
Agriculture. It's all we do. L'agriculture... notre raison d'être.
This message may contain information that is privileged, protected,
confidential or subject to copyright. Using, disclosing, copying or
distributing such information by anyone other than the intended recipient is
strictly prohibited. If you’ve received this message in error, please delete
it and notify me immediately.
Le présent courriel contient des renseignements de nature privilégiée,
protégée, confidentielle ou assujettie à des droits d’auteur. Toute
utilisation, communication, reproduction ou distribution de l’information
contenue dans ce courriel par toute personne autre que le destinataire visé
est strictement interdite. Si vous avez reçu ce courriel par erreur,
veuillez le supprimer et m’en informer immédiatement.
-----Original Message-----
From: Janak Mulani [mailto:[EMAIL PROTECTED]
Sent: September 4, 2006 12:43 PM
To: Kliman, Elizabeth
Cc: ULC Developer List (E-mail)
Subject: RE: [ULC-developer] ULC 6.1 Currency extension and Locale


Hi Elisabeth,
Was it working in ULC 6.0.4?
Could you please send me UICurrencyAmountDataType and
ULCCurrencyAmountDataType classes?
Thanks and regards,
Janak
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Kliman, Elizabeth
Sent: Saturday, September 02, 2006 3:40 AM
To: ULC Developer List (E-mail)
Subject: [ULC-developer] ULC 6.1 Currency extension and Locale


Hi,
We have converted our entire application to ULC 6.1 recently and just
realized that our currency data type extension does not work properly in the
CANADA_FRENCH locale.
The currency data type extension that we have created extends from
ULCNumberDataType and UINumberDataType.  In our UICurrencyAmountDataType we
override convertToString and convertToObject methods so that we can apply
our currency formatting.
In English everything works as expected.  In French, values will not
display, although if you have an editable text field with a
ULCCurrencyAmountDataType, it will format any data that you type in
correctly.  However, if you save that data, when you return to that screen
the value is gone.
I have been debugging through the overridden methods convertToString and
convertToObject in UICurrencyAmountDataType and printing out various values.
It seems as though the value is getting lost somewhere in the super class.
On one method call, the value is there and seems to be translated properly,
and the next method call we're dealing with a null object.  The end result
is that an empty string gets displayed.
Any idea what could be causing this?
Thanks.
Elizabeth Kliman, B.Sc., SCJP
Developer / Développeur
Information Technology / Technologie de l'information
Farm Credit Canada / Financement agricole Canada
1800 Hamilton Street, P.O. Box 4320
1800, rue Hamilton, C.P. 4320
Regina SK S4P 4L3
Tel/Tél. : (306) 780-3382 Fax/Télec. : (306) 780-5655
E-mail/Courriel : [EMAIL PROTECTED]
Agriculture. It's all we do. L'agriculture... notre raison d'être.
This message may contain information that is privileged, protected,
confidential or subject to copyright. Using, disclosing, copying or
distributing such information by anyone other than the intended recipient is
strictly prohibited. If you’ve received this message in error, please delete
it and notify me immediately.
Le présent courriel contient des renseignements de nature privilégiée,
protégée, confidentielle ou assujettie à des droits d’auteur. Toute
utilisation, communication, reproduction ou distribution de l’information
contenue dans ce courriel par toute personne autre que le destinataire visé
est strictement interdite. Si vous avez reçu ce courriel par erreur,
veuillez le supprimer et m’en informer immédiatement.

Attachment: DollarInCurrencyDataTypeSnippet.java
Description: Binary data

Attachment: SwingDollarInCurrencyDataTypeSnippet.java
Description: Binary data

Reply via email to