⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inputelement.java

📁 ZK 基础介绍 功能操作 模块 结合数据库操作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}	/** Returns the tab order of this component.	 * <p>Default: -1 (means the same as browser's default).	 */	public int getTabindex() {		return _tabindex;	}	/** Sets the tab order of this component.	 */	public void setTabindex(int tabindex) throws WrongValueException {		if (_tabindex != tabindex) {			_tabindex = tabindex;			if (tabindex < 0) smartUpdate("tabindex", null);			else smartUpdate("tabindex", Integer.toString(_tabindex));		}	}	/** Returns whether it is multiline.	 * <p>Default: false.	 */	public boolean isMultiline() {		return false;	}	/** Returns the type.	 * <p>Default: text.	 */	public String getType() {		return "text";	}	/** Selects the whole text in this input.	 */	public void select() {		smartUpdate("z.sel", "all");	}	//-- Constrainted --//	public void setConstraint(String constr) {		_constr = SimpleConstraint.getInstance(constr);		_valided = false;		invalidate(); //regenerate attributes	}	public void setConstraint(Constraint constr) {		if (_constr != constr) {			_constr = constr;			invalidate();		}	}	public final Constraint getConstraint() {		return _constr;	}	//-- super --//	/** Returns whether to send back the request of the specified event	 * immediately -- non-deferable.	 * Returns true if you want the component (on the server)	 * to process the event immediately.	 *	 * <p>Default: Besides super.isAsapRequired(evtnm), it also returns true	 * if evtnm is Events.ON_CHANGE, {@link #getConstraint} is not null,	 * and {@link ClientConstraint#getClientValidation} is null.	 */	protected boolean isAsapRequired(String evtnm) {		return (Events.ON_CHANGE.equals(evtnm) && _constr != null			&& ((_constr instanceof CustomConstraint)				|| !(_constr instanceof ClientConstraint)				|| !((ClientConstraint)_constr).isClientComplete()))			|| super.isAsapRequired(evtnm);	}	public String getInnerAttrs() {		final StringBuffer sb =			new StringBuffer(64).append(super.getInnerAttrs());		if (isMultiline()) {			if (_cols > 0)				HTMLs.appendAttribute(sb, "cols",  _cols);			if (_maxlength > 0)				HTMLs.appendAttribute(sb, "z.maxlen",  _maxlength);		} else {			HTMLs.appendAttribute(sb, "value",  coerceToString(_value));			if (_cols > 0)				HTMLs.appendAttribute(sb, "size",  _cols);			if (_maxlength > 0)				HTMLs.appendAttribute(sb, "maxlength",  _maxlength);			HTMLs.appendAttribute(sb, "type", 				"password".equals(getType()) ? "password": "text");		}		if (_tabindex >= 0)			HTMLs.appendAttribute(sb, "tabindex", _tabindex);		HTMLs.appendAttribute(sb, "name", _name);		if (isDisabled())			HTMLs.appendAttribute(sb, "disabled",  "disabled");		if (isReadonly())			HTMLs.appendAttribute(sb, "readonly", "readonly");		return sb.toString();	}	public String getOuterAttrs() {		final StringBuffer sb =			new StringBuffer(64).append(super.getOuterAttrs());		appendAsapAttr(sb, Events.ON_CHANGE);		appendAsapAttr(sb, Events.ON_CHANGING);		appendAsapAttr(sb, Events.ON_FOCUS);		appendAsapAttr(sb, Events.ON_BLUR);		appendAsapAttr(sb, Events.ON_SELECTION);		if (_constr != null) {			String serverValid = null;			if (_constr instanceof CustomConstraint) {				serverValid = "custom";					//validate-at-server is required and no client validation			} else if (_constr instanceof ClientConstraint) {				final ClientConstraint cc = (ClientConstraint)_constr;				HTMLs.appendAttribute(sb, "z.valid",					toJavaScript(cc.getClientValidation()));				HTMLs.appendAttribute(sb, "z.ermg", cc.getErrorMessage(this));				if (!cc.isClientComplete())					serverValid = "both";					//validate-at-server is required after the client validation			} else {				serverValid = "both";			}			HTMLs.appendAttribute(sb, "z.srvald", serverValid);		}		return sb.toString();	}	/** Converts the client validation to JavaScript.	 */	private final String toJavaScript(String script) {		return script != null ?			script.indexOf('(') >= 0 ?				ComponentsCtrl.parseClientScript(this, script):				script: null;	}	/** Returns the value in the targeting type.	 * It is used by the deriving class to implement the getValue method.	 * For example, {@link org.zkoss.zul.Intbox#getValue} is the same	 * as this method except with a different signature.	 *	 * <p>It invokes {@link #checkUserError} to ensure no user error.	 * @exception WrongValueException if the user entered a wrong value	 * @see #getText	 */	protected Object getTargetValue() throws WrongValueException {		checkUserError();		return _value;	}	/** Returns the raw value directly with checking whether any	 * error message not yet fixed. In other words, it does NOT invoke	 * {@link #checkUserError}.	 *	 * <p>Note: if the user entered an incorrect value (i.e., caused	 * {@link WrongValueException}), the incorrect value doesn't	 * be stored so this method returned the last correct value.	 *	 * @see #getRawText	 * @see #getText	 * @see #setRawValue	 */	public Object getRawValue() {		return _value;	}	/** Returns the text directly without checking whether any error	 * message not yet fixed. In other words, it does NOT invoke	 * {@link #checkUserError}.	 *	 * <p>Note: if the user entered an incorrect value (i.e., caused	 * {@link WrongValueException}), the incorrect value doesn't	 * be stored so this method returned the last correct value.	 *	 * @see #getRawValue	 * @see #getText	 */	public String getRawText() {		return coerceToString(_value);	}	/** Sets the raw value directly. The caller must make sure the value	 * is correct (or intend to be incorrect), because this method	 * doesn't do any validation.	 *	 * <p>If you feel confusing with setValue, such as {@link org.zkoss.zul.Textbox#setValue},	 * it is usually better to use setValue instead. This method	 * is reserved for developer that really want to set an 'illegal'	 * value (such as an empty string to a textbox with no-empty contraint).	 *	 * <p>Like setValue, the result is returned back to the server	 * by calling {@link #getText}.	 *	 * @see #getRawValue	 */	public void setRawValue(Object value) {		if (_errmsg != null || !Objects.equals(_value, value)) {			clearErrorMessage();			_value = value;			smartUpdate("value", coerceToString(_value));		}	}	/** Returns the current content of this input is correct.	 * If the content is not correct, next call to the getvalue method will	 * throws WrongValueException.	 */	public boolean isValid() {		if (_errmsg != null)			return false;		if (!_valided && _constr != null) {			try {				validate(_value);			} catch (Throwable ex) {				return false;			}		}		return true;	}	/**	 * Sets the text of this InputElement to the specified text which is	 * begining with the new start point and ending with the new end point.	 * 	 * @param start the start position of the text (included)	 * @param end the end position of the text (excluded)	 * @param newtxt the new text to be set.	 * @param isHighLight	 *            Sets whether it will represent highlihgt style or cursor	 *            style.If the start point same with the end point always	 *            represent cursor style.	 */	public void setSelectedText(int start, int end, String newtxt,			boolean isHighLight) {		if (start <= end) {			final String txt = getText();			final int len = txt.length();			if (start < 0) start = 0;			if (start > len) start = len;			if (end < 0) end = 0;			if (end > len) end = len;			if (newtxt == null)				newtxt = "";			setText( txt.substring(0, start) + newtxt + txt.substring(end));			setSelectionRange(start,				isHighLight ? start + newtxt.length(): start);		}	}	/**	 * Sets the selection end to the specified position and the selection start	 * to the specified position. The new end point is constrained to be at or	 * after the current selection start. If the new start point is different	 * with the new end point, then will represent the result of highlight in	 * this text.	 *	 * <p>Set both arguments to the same value to move the cursor to	 * the corresponding position without selecting text.	 * 	 * @param start the start position of the text (included)	 * @param end the end position of the text (excluded)	 */	public void setSelectionRange(int start, int end) {		if (start <= end)			smartUpdate("z.sel", start + "," + end);	}	/** Checks whether user entered a wrong value (and not correct it yet).	 * Since user might enter a wrong value and moves on to other components,	 * this methid is called when {@link #getText} or {@link #getTargetValue} is	 * called.	 *	 * <p>Derives rarely need to access this method if they use only	 * {@link #getText} and {@link #getTargetValue}.	 */	protected void checkUserError() throws WrongValueException {		if (_errmsg != null)			throw showCustomError(new WrongValueException(this, _errmsg));				//Note: we still throw exception to abort the exec flow				//It's client's job NOT to show the error box!				//(client checks z.srvald to decide whether to open error box)		if (!_valided && _constr != null)			setText(coerceToString(_value));	}	/** Returns the text for HTML AREA (Internal Use Only).	 *	 * <p>Used only for component generation. Not for applications.	 */	public String getAreaText() {		return XMLs.encodeText(coerceToString(_value));	}	//-- Component --//	/** Not childable. */	public boolean isChildable() {		return false;	}	//-- ComponentCtrl --//	protected Object newExtraCtrl() {		return new ExtraCtrl();	}	public WrongValueException onWrongValue(WrongValueException ex) {		_errmsg = Exceptions.getMessage(ex);		return showCustomError(ex);	}	/** A utility class to implement {@link #getExtraCtrl}.	 * It is used only by component developers.	 */	protected class ExtraCtrl extends XulElement.ExtraCtrl	implements Inputable, Errorable {		//-- Inputable --//		public void setTextByClient(String value) throws WrongValueException {			_txtByClient = value;			try {				setText(value);			} catch (WrongValueException ex) {				_errmsg = ex.getMessage();					//we have to 'remember' the error, so next call to getValue					//will throw an exception with proper value.				throw ex;			} finally {				_txtByClient = null;			}		}		//-- Errorable --//		public void setErrorByClient(String value, String msg) {			_errmsg = msg != null && msg.length() > 0 ? msg: null;		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -