Announcement Announcement Module
Collapse
No announcement yet.
change default value using spring-form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Change the default value for double field from 0.0 to 0

    Hi Guys
    I'm having the exact issue and this is my first time with Spring. After going through all the google results and examples. This is what I've written in my controller but my getAsText() method never seems to get called. I have tested it in debug and the method never gets called.

    This is the initBinder method in my controller. The initBinder() method itself gets called and the CustomNumberEditor is registered.

    Its just that the getAsText never gets called and I've switched to using javascript to get it working for now. But I really do want to do it the proper way before we go live.

    Code:
        @Override
        protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
        	DecimalFormat balanceFormat = new DecimalFormat("0.##");
        	balanceFormat.setDecimalSeparatorAlwaysShown(false);
    	    CustomNumberEditor editor = new CustomNumberEditor(Double.class,balanceFormat, true) {
    	    	
    	    	@Override
    	    	public String getAsText()
    	    	{
    	    		Object value = getValue();
    				if(value == null)
    					return "0";
    				else
    					return super.getAsText();
    	    	}
    	    	
    	    	    	
    	    };
    	    binder.registerCustomEditor(Double.class, editor);
    	    super.initBinder(request, binder);
        }
    Any help would be greatly appreciated.

    Chinto
    Last edited by Chinto; Mar 9th, 2009, 06:47 PM.

    Comment

    Working...
    X