wicketã®ä½è¨ãªãä¸è©±ã«çµ¶æããï¼wicket1.3ã®ãã³ãã¼ãã©ã¼ãããã®ãã°
PropertyModelçã§BigDecimalã«ãããã³ã°ããTextFieldãä½ã£ã¦ã10000000â¦ã¨å ¥ãã¦ã¿ã¦ä¸ããã
100,000,000,000,000,000,000,000,000,000
ã¨ãã©ã¼ããããã¦è¡¨ç¤ºãããããã«ãªã£ã¦ããã®ã§ãã
ã¡ãã£ã¨åä½ã追ã£ã¦ã¿ã¾ããã1.3.0ã¯ãã©ã¼ãããããªãã£ãã®ã§ã1.3.1ããã®ããã§ããï¼1.3.3ã¾ã§ç¢ºèªï¼
ReleaseNoteãè¦ã¦ã¿ã¾ãããé¢ä¿ãããããªã®ã¯[WICKET-1254] Binding to a BigDecimal don't honor browser locale - ASF JIRAãããã§ãããç´æ¥é¢ä¿ãããã§ããããï¼
ãã®æç¹ã§ãã©ã¼ãããããããªã人ã¯å°ãã¨æãã¾ããããã24æ¡ä»¥ä¸å ¥åããã¨åãããã§ããã
âã®å¤ã¯âã¨ãªãã¾ãã
99,999,999,999,999,991,433,150,857,216
å
¥åããæååãBigDecimalConverterã§Convertãã¦ããã§ãããã½ã¼ã¹ããæç²ãã¦ããããããããã¨ä»¥ä¸ã®ãããªåä½ã«ãªã£ã¦ã¾ããã
BigDecimal hoge = new BigDecimal("100000000000000000000000000000"); System.out.println(hoge); NumberFormat nf = NumberFormat.getInstance(locale); //ålocaleã§NumberFormatãåå¾ãã¦å¤ãæååã«ãã©ã¼ããã String formatString = nf.format(hoge); System.out.println(formatString); try { ãããããããã//åãNumberFormatã«ãã©ã¼ãããããæååãå ¥ããã¨Doubleã«ãªãã Double parseObject = (Double) nf.parseObject(formatString); System.out.println(parseObject); ãããããããã//DoubleãBigDecimalã«ååº¦å ¥ããã¨ããã§ç²¾åº¦åé¡ã§åãã System.out.println(new BigDecimal(parseObject.doubleValue())); } catch (ParseException e) { }
åºåã¯ãããªãã¾ã
100000000000000000000000000000 100,000,000,000,000,000,000,000,000,000 1.0E29 99999999999999991433150857216
ã¨ãããã¨ã§javaã®NumberFormatèªä½ãParseæã«Doubleãè¿ãã¦ãã¦ãBigDecimalã«å
¥ããã¨åããã®ã§wicketã®ããã§ã¯ãªããããªæ°ããã¾ãâ¦ãï¼
ããããwicketãä½è¨ãªäºãã¦ãã®ãæªãã¨æãã¾ãã
ãã©ã¼ãããããããã°èªåã§ã«ã¹ã¿ã ã³ã³ãã¼ãã³ããä½ããããã§ãããwicketå´ã§ãã£ã¦ãããã«ãã¦ããã©ã¼ãããããConverterãè¨å®ããã³ã³ãã¼ãã³ãã®æä¾çé常ã¯ä½ãããªãã§ãå¿ è¦ãªã¨ãã ããã©ã¼ããããã¦ãããæ¹æ³ã¯ä»ã«ãããããã§ããã
IConverterのエラーメッセージを変更する - 凡人プログラマãããã§ãããããã¾ãä½è¨ãªæåã¯å ¥ãã¦æ¬²ãããªãã§ãããããããã®ã¯extensionçã«å ¥ããã¹ããããªãããªã¼ã¨ã
ãããªã¬ã¢ãªåé¡ã§å°ã£ã¦ããä¸éãªæ¹ã®çºã«å¯¾å¦æ³ãæ¸ãã¦ããã¾ã
- Application#newConverterLocatorããªã¼ãã¼ã©ã¤ããã¦ãèªä½ConverterLocatorãä½æãBigDecimalã®ã³ã³ãã¼ã¿ãç½®ãæããã
- åé¡çºçããTextFieldã§getConverterãå®ç¾©ãã¦ãããèªä½Converterãè¿ãã
ã¡ãªã¿ã«ä»¥ä¸ã®èªä½Converterã¯ä¸è¨ãã°ãä¿®æ£ããçã§ããTextFieldã«getConverterãå®ç¾©ãã¦åé¡çºçããªãäºã確èªãã¾ããã
BigDecimalãçæããé¨åã§number.doubleValue()ã§ã¯ç¡ããnumber.toString()ã«ãã¾ãããï¼ããã対ççæ³ã£ã½ãã§ããï¼
æ¬å®¶ã®ãã°ããããä¿®æ£ããã ãã§ç´ãã¨æãã¾ãã
return new IConverter() { @Override public Object convertToObject(String value, Locale locale) { Number number = null; try { number = NumberFormat.getInstance(locale).parse(value); } catch (ParseException e) { e.printStackTrace(); } return new BigDecimal(number.toString()); } @Override public String convertToString(Object value, Locale locale) { return NumberFormat.getInstance(locale).format(value); } };