ZK LOCALE DecimalBox 转换
ZK LOCALE DecimalBox conversion
求助。
当我使用 ZK 的 decimalBox 并且用户的 Locale 是 IT 时,小数点被转换为逗号,这使我的计算变得混乱。请问我怎样才能停止转换?
我正在使用 ZK 6.5.7
有几种解决方案。
您可以像 here.
一样将 Webapp 的区域设置设置为 EN
您可以为 Decimalbox 定义 "format" 属性。
或者您可以在 ZUL 中的简单事件处理程序中执行此操作,如 that forum:
action="onkeyup:#{self}.value = #{self}.value.replace('.',',');"
这里是小数框的代码,它允许指定用于格式化小数的符号:
package ch.swissquant.zurich.abt.questionnaire.zk;
import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.zkoss.json.JSONValue;
import org.zkoss.zul.Decimalbox;
public class SymbolDecimalbox extends Decimalbox {
private static final long serialVersionUID = 1L;
private DecimalFormatSymbols symbols;
private Locale locale;
/** Hide the parent method to make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called. */
@Override
public void setLocale(Locale locale) {
this.locale = locale;
}
/** Hide the parent method to make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called. */
@Override
public Locale getLocale() {
return locale;
}
public void setSymbols(DecimalFormatSymbols symbols) {
this.symbols = symbols;
}
public DecimalFormatSymbols getSymbols() {
return symbols;
}
//super//
@Override
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
throws java.io.IOException {
super.renderProperties(renderer);
// By overriding setLocale(), we make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called.
renderer.render("localizedSymbols", getRealSymbols());
}
/** Send the specified symbols to the UI. */
private String getRealSymbols() {
if (symbols != null && locale != null) {
Map<String, String> map = new HashMap<String, String>();
map.put("GROUPING",
String.valueOf(symbols.getGroupingSeparator()));
map.put("DECIMAL",
String.valueOf(symbols.getDecimalSeparator()));
map.put("PERCENT", String.valueOf(symbols.getPercent()));
map.put("PER_MILL", String.valueOf(symbols.getPerMill()));
map.put("MINUS", String.valueOf(symbols.getMinusSign()));
final String localeName = locale.toString();
return JSONValue.toJSONString(new Object[] { localeName, map });
}
return null;
}
}
求助。
当我使用 ZK 的 decimalBox 并且用户的 Locale 是 IT 时,小数点被转换为逗号,这使我的计算变得混乱。请问我怎样才能停止转换?
我正在使用 ZK 6.5.7
有几种解决方案。
您可以像 here.
一样将 Webapp 的区域设置设置为 EN您可以为 Decimalbox 定义 "format" 属性。
或者您可以在 ZUL 中的简单事件处理程序中执行此操作,如 that forum:
action="onkeyup:#{self}.value = #{self}.value.replace('.',',');"
这里是小数框的代码,它允许指定用于格式化小数的符号:
package ch.swissquant.zurich.abt.questionnaire.zk;
import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.zkoss.json.JSONValue;
import org.zkoss.zul.Decimalbox;
public class SymbolDecimalbox extends Decimalbox {
private static final long serialVersionUID = 1L;
private DecimalFormatSymbols symbols;
private Locale locale;
/** Hide the parent method to make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called. */
@Override
public void setLocale(Locale locale) {
this.locale = locale;
}
/** Hide the parent method to make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called. */
@Override
public Locale getLocale() {
return locale;
}
public void setSymbols(DecimalFormatSymbols symbols) {
this.symbols = symbols;
}
public DecimalFormatSymbols getSymbols() {
return symbols;
}
//super//
@Override
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
throws java.io.IOException {
super.renderProperties(renderer);
// By overriding setLocale(), we make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called.
renderer.render("localizedSymbols", getRealSymbols());
}
/** Send the specified symbols to the UI. */
private String getRealSymbols() {
if (symbols != null && locale != null) {
Map<String, String> map = new HashMap<String, String>();
map.put("GROUPING",
String.valueOf(symbols.getGroupingSeparator()));
map.put("DECIMAL",
String.valueOf(symbols.getDecimalSeparator()));
map.put("PERCENT", String.valueOf(symbols.getPercent()));
map.put("PER_MILL", String.valueOf(symbols.getPerMill()));
map.put("MINUS", String.valueOf(symbols.getMinusSign()));
final String localeName = locale.toString();
return JSONValue.toJSONString(new Object[] { localeName, map });
}
return null;
}
}