cancel
Showing results for 
Search instead for 
Did you mean: 

ISimpleTypeModifiable. UnsupportedOperationException on setLocale method

Former Member
0 Kudos

Hi,

I have some context attribute(build in decimal type), and want to configure output view(grouping and decimal separators) of this value on UI components for different users using ISimpleTypeModifiable interface. I didn't find any setter methods for Formatter(NumberFormat interface). So, I have tried to use setLocale method(different locales have different separators: "RU" locale output for ex. - 123 456,78), but it throws UnsupportedOperationException. Here is some simple code to describe this situation:


ISimpleTypeModifiable type = attrInfo.getModifiableSimpleType();
type.setLocale(new Locale("some locale"));
type.setFormat("some format");

If there is some other way to configure output view for decimal attributes without changing attribute type?

Thanks

Edited by: Mikhail Udalov on Nov 10, 2008 3:30 PM

Edited by: Mikhail Udalov on Nov 10, 2008 3:30 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, Mikhail!

The simplest solution is to configure (or change in runtime - if it possible) user's locale.

Also you can create calculated read only attribute of type string and use it for presenting your decimal value in right format. Something like this:


// get method of calculated attribute
final NumberFormat format = NumberFormat.getInstance(locale);
return format.format(numericValue);

More one solution is creating "right localized" attribute dynamically:


final ISimpleType decimalType = attrInfo.getSimpleType(); // some decimal attribute created in designer
final ISimpleTypeModifiable localizedDecimal = decimalType.cloneType(locale);
localizedDecimal.setFormat("some format"); // specify format if need
nodeInfo.addAttribute("DecimalValue", localizedDecimal);

Former Member
0 Kudos

Hi, Pavel.

I think the second solution is that, what I need! How could I miss cloneType(Locale newLocale) method in API .. )

Thanks a lot! Mikhail

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Have you tried with a dictionary type?

Regards

Ayyapparaj

Former Member
0 Kudos

Hi, Yes I have tried to use dictionary types, but it didn't help. I need to change decimal and grouping separators symbols at runtime according with user choice.

Former Member
0 Kudos

Hi,

I assume that you are getting the values as decimal and want to display it to users in some user-specific formats:

for(int i=0; i<wdContext.node<nodename>().size();i++)

{

DecimalFormat d = new DecimalFormat("#,##,###");

String value = d.format(wdContext.node<nodename>(i).get<DecimalAttribute>());;

//Assign the above string value to the field that you want to display to the user.

}

Regards,

Murtuza

Former Member
0 Kudos

Hi, Murtuza.

Yes, it is possible to use strings. But we have a lot of editable fields mapped to decimals attributes, so I want find decision without using strings(I can use build-in portal validation and don't have to do internal string-double conversions in this way)

Thanks, Mikhail

Former Member
0 Kudos

The reason was that

attrInfo.getModifiableSimpleType()

returns ModifiableSimpleType instance on runtime(not DdTypeDecimal as I thought before) that wraps DdTypeDecimal instance and throws UnsupportedOperationException on setLocale method. setFormat works fine but I still can't change decimal and grouping separators