Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-631

Datebox format error message not shown with implements CustomConstraint

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • None
    • 5.0.9
    • Components

      From forum http://www.zkoss.org/forum/listComment/18012
      When implementing CustomConstraint, the customShowError can't handle Datebox format error.
      [index.zul]

      <zk>
      	<window id="win" apply="test.DateController" >
      		<datebox id="dob" width="200px" visible="true" format="yyyy/MM/dd" lenient="false"/>
      		<label id="doberr" />
      	</window>
      </zk>
      

      [DateControll.java]

      package test;
      
      import org.zkoss.zk.ui.Component;
      import org.zkoss.zk.ui.util.GenericForwardComposer;
      import org.zkoss.zul.Datebox;
      import org.zkoss.zul.Label;
      
      public class DateController extends GenericForwardComposer {
      	private static final long serialVersionUID = 1L;
      
      	// Form fields; auto-wired.
      	private Datebox dob;
      	private Label doberr;
      
      	public void doAfterCompose(Component comp) throws Exception{
      		super.doAfterCompose(comp);
      		dob.setConstraint(new MyDateConstraint(doberr, MyDateConstraint.STRICT
      				| MyDateConstraint.SERVER | MyDateConstraint.NO_FUTURE
      				| MyDateConstraint.NO_TODAY));
      
      	}
      }
      

      [MyDateConstraint.java]

      package test;
      
      import org.zkoss.util.logging.Log;
      import org.zkoss.zk.ui.Component;
      import org.zkoss.zk.ui.WrongValueException;
      import org.zkoss.zul.CustomConstraint;
      import org.zkoss.zul.Datebox;
      import org.zkoss.zul.Label;
      import org.zkoss.zul.SimpleDateConstraint;
      
      public class MyDateConstraint extends SimpleDateConstraint implements CustomConstraint{
      	
      	private static final long serialVersionUID = 1L;
      	private static Log log = Log.lookup(MyDateConstraint.class);
      	private Label errfld;
      
      	public MyDateConstraint(Label errlbl, int flags) {
      		super(flags);
      		errfld = errlbl;
      	}
      	
      	public void showCustomError(Component comp, WrongValueException ex) {
      		System.out.println("showCustomError");
      		if (ex != null) {
      			log.debug("WrongValueException Message: " + ex.getMessage());
      			errfld.setValue(ex.getMessage());
      			errfld.setVisible(true);
      		} else {
      			log.debug("No exception");
      			if (comp instanceof Datebox) {
      				log.debug("datebox error message is: "
      						+ ((Datebox) comp).getErrorMessage());
      			} else
      				log.debug("comp is: " + comp.getClass().getName());
      
      			errfld.setVisible(false);
      		}
      	}
      
      }
      

            benbai benbai
            vincentjian vincentjian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: