帮助。
当我使用ZK的decimalBox并且用户的Locale是IT时,小数点会转换为逗号,这会混淆我的计算。我怎么能停止转换呢?
我使用的是ZK 6.5.7
答案 0 :(得分:1)
有几个解决方案。
您可以将Webapp的区域设置设置为EN,如here。
您可以定义"格式"您的Decimalbox的属性。
或者您可以在ZUL中的简单事件处理程序中执行此操作,例如that forum:
action="onkeyup:#{self}.value = #{self}.value.replace('.',',');"
答案 1 :(得分:0)
以下是十进制框的代码,它允许指定用于格式化十进制数字的符号:
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;
}
}