/**
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 * If a copy of the MPL was not distributed with this file, You can obtain one at
 * http://mozilla.org/MPL/2.0/.
 * 
 * This Source Code Form is also subject to the terms of the Health-Related Additional
 * Disclaimer of Warranty and Limitation of Liability available at
 * http://www.carewebframework.org/licensing/disclaimer.
 */
package org.carewebframework.ui.zk;

import java.util.Date;

import org.carewebframework.common.DateUtil;

import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Datebox;

/**
 * Extends the ZK datebox by enhancing date parsing.
 */
public class DateboxEx extends Datebox {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * Parses the input value using enhanced date parsing.
     * 
     * @param value String value to parse.
     * @return A Date object resulting from the parsed value.
     * @throws WrongValueException If invalid input value.
     */
    @Override
    protected Object coerceFromString(String value) throws WrongValueException {
        if (value == null || value.length() == 0) {
            return null;
        }
        
        Date date = DateUtil.parseDate(value);
        
        if (date == null) {
            return super.coerceFromString(value);
        }
        
        return date;
    }
    
    /**
     * Returns the value as a string.
     * 
     * @param value Object to transform.
     * @return Object value as a string.
     */
    @Override
    protected String coerceToString(Object value) {
        return value instanceof String ? (String) value : super.coerceToString(value);
    }
    
}

@@ -761,24 +761,139 @@
  = 1L;%0A    %0A
+    public DateboxEx() %7B%0A        super();%0A        setFormat(DateUtil.Format.WITHOUT_TIME.getPattern());%0A    %7D%0A    %0A
     /**%0A    

Set default date format for DateboxEx to be consistent with that used by DateUtil.formatDate.