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

Datebox format error message not shown with implements CustomConstraint

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 5.0.9
    • Fix Version/s: None
    • Component/s: Components

      Description

      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);
      		}
      	}
      
      }
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: