01: /* FormatInputElement.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Jul 5 09:27:34 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul.impl;
20:
21: import org.zkoss.lang.Objects;
22:
23: import org.zkoss.zk.ui.WrongValueException;
24: import org.zkoss.zk.ui.event.Events;
25:
26: /**
27: * A skeletal implementation for an input box with format.
28: *
29: * @author tomyeh
30: */
31: abstract public class FormatInputElement extends InputElement {
32: private String _format;
33:
34: /** Returns the format.
35: * <p>Default: null (used what is defined in the format sheet).
36: */
37: public String getFormat() {
38: return _format;
39: }
40:
41: /** Sets the format.
42: */
43: public void setFormat(String format) throws WrongValueException {
44: if (!Objects.equals(_format, format)) {
45: final String old = _format;
46: _format = format;
47: smartUpdate("z.fmt", getFormat());
48:
49: try {
50: smartUpdate("value", getText());
51: //Yes, the value attribute is changed! (no format attr in client)
52: } catch (WrongValueException ex) {
53: //ignore it (safe because it will keep throwing exception)
54: }
55: }
56: }
57:
58: //-- super --//
59: public String getOuterAttrs() {
60: final String attrs = super .getOuterAttrs();
61: final String fmt = getFormat();
62: return fmt != null && fmt.length() != 0 ? attrs + " z.fmt=\""
63: + fmt + '"' : attrs;
64: }
65:
66: protected boolean isAsapRequired(String evtnm) {
67: return (Events.ON_CHANGE.equals(evtnm) && getFormat() != null)
68: || super.isAsapRequired(evtnm);
69: }
70: }
|