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

📄 radiofield.java

📁 OBPM是一个开源
💻 JAVA
字号:
//Source file:
//C:\\Java\\workspace\\SmartWeb3\\src\\com\\cyberway\\dynaform\\form\\ejb\\SelectField.java

package cn.myapps.core.dynaform.form.ejb;

import java.util.Iterator;

import cn.myapps.base.action.ParamsTable;
import cn.myapps.core.dynaform.PermissionType;
import cn.myapps.core.dynaform.document.ejb.Document;
import cn.myapps.core.dynaform.document.ejb.Item;
import cn.myapps.core.macro.runner.JavaScriptRunner;
import cn.myapps.core.user.action.WebUser;
import cn.myapps.core.validate.repository.ejb.ValidateRepositoryProcess;
import cn.myapps.core.validate.repository.ejb.ValidateRepositoryVO;
import cn.myapps.util.Debug;
import cn.myapps.util.HtmlEncoder;
import cn.myapps.util.ProcessFactory;
import cn.myapps.util.StringList;
import cn.myapps.util.StringUtil;

public class RadioField extends FormField {

	protected static String cssClass = "radio-cmd";

	/**
	 * 计算多值选项
	 */
	protected String optionsScript;

	protected String validateLibs = "";

	public String getValidateLibs() {
		return validateLibs;
	}

	public void setValidateLibs(String validateLibs) {
		this.validateLibs = validateLibs;
	}

	/**
	 * @roseuid 41ECB66D031D
	 */
	public RadioField() {

	}

	/**
	 * @return Returns the optionsScript.
	 */
	public String getOptionsScript() {
		return optionsScript;
	}

	/**
	 * @param optionsScript
	 *            The optionsScript to set.
	 */
	public void setOptionsScript(String optionsScript) {
		this.optionsScript = optionsScript;
	}

	/**
	 * @return boolean
	 * @roseuid 41ECB66D0331
	 */
	public ValidateMessage validate(JavaScriptRunner runner, Document doc)
			throws Exception {
		Object result = null;
		String rtn = "";
		ValidateMessage msg = new ValidateMessage();
		if (getValidateLibs() != null && getValidateLibs().trim().length() > 0) {
			String libs[] = getValidateLibs().split(";");
			ValidateRepositoryProcess vp = (ValidateRepositoryProcess) ProcessFactory
					.createProcess(ValidateRepositoryProcess.class);
			for (int i = 0; i < libs.length; i++) {
				ValidateRepositoryVO vo = (ValidateRepositoryVO) vp
						.doView(libs[i]);
				String cotent = "";
				String functionName = getFunctionNames(vo.getContent());
				if (functionName != null) {
					cotent += functionName + "('" + getName() + "');";
					cotent += vo.getContent();
					Object obj = runner.run(cotent);
					if (obj instanceof String) {
						rtn += (String) obj;
					}
				}
			}
		}

		if (getValidateRule() != null && getValidateRule().trim().length() > 0) {
			result = runner.run(StringUtil.dencodeHTML(getValidateRule()));
			System.out.print(getValidateLibs());
			// Item item = doc.findItem(this.getName());
			if (result instanceof String) {
				String rs = (String) result;
				if (rs != null && rs.trim().length() > 0) {
					rtn += rs;

				}
			}
		}
		if (rtn != null && rtn.trim().length() > 0) {
			msg.setFieldname(this.getName());
			msg.setErrmessage(rtn);
			return msg;
		} else
			return null;
	}

	public String getFunctionNames(String content) {

		if (content == null || content.trim().length() == 0)
			return null;
		int i = content.indexOf("function");
		int j = content.substring(i + 8, content.length()).indexOf("(");
		String functionname = content.substring(i + 8, i + 8 + j);
		if (functionname != null && functionname.trim().length() > 0)
			return functionname;
		else
			return null;
	}

	/**
	 * 重新计算
	 * 
	 * @roseuid 41DB89D700F9
	 */
	public void recalculate(JavaScriptRunner runner, Document doc)
			throws Exception {
		Debug.println("RadioField.recalculate");
		recalculate(runner, doc, PermissionType.MODIFY);
	}

	public void recalculate(JavaScriptRunner runner, Document doc,
			int displayType) throws Exception {
		Debug.println("RadioField.recalculate");
		runValueScript(runner, doc);
		runOptionsScript(runner, doc);
	}

	/*
	 * 运行计算Field值Script,返回值即为计算结果。
	 * 
	 * @return java.lang.String @roseuid 41DB8C1E03E7
	 */
	public Object runValueScript(JavaScriptRunner runner, Document doc)
			throws Exception {
		Object result = null;

		if (getValueScript() != null && getValueScript().trim().length() > 0) {
			System.out.println("JavaScript->"
					+ StringUtil.dencodeHTML(getValueScript()));
			result = runner.run(StringUtil.dencodeHTML(getValueScript()));
			Item item = doc.findItem(this.getName());
			item.setValue(result);
		}
		return result;
	}

	/**
	 * @param doc
	 * @return java.lang.String
	 * @roseuid 41ECB66D034F
	 */
	public String toHtmlTxt(ParamsTable params, WebUser user,
			JavaScriptRunner runner, Document doc) {
		StringBuffer html = new StringBuffer();
		try {
			html.append(runOptionsScript(runner, doc));
		} catch (Exception e) {
			e.printStackTrace();
		}

		return html.toString();
	}

	public String toPrintHtmlTxt(ParamsTable params, WebUser user,
			JavaScriptRunner runner, Document doc) throws Exception {
		Object result = null;
		StringBuffer html = new StringBuffer();

		if (doc != null
				&& !(getPrintDisplayType(runner, doc) == PermissionType.HIDDEN)) {
			if (getOptionsScript() != null
					&& getOptionsScript().trim().length() > 0) {
				result = runner.run(StringUtil.dencodeHTML(getOptionsScript()));

				Options options = null;
				if (result != null && result instanceof String) {

					String[] strlst = ((String) result).split(";");
					options = new Options();
					for (int i = 0; i < strlst.length; i++) {
						options.add(strlst[i], strlst[i]);
					}
				} else if (result instanceof Options) {
					options = (Options) result;
				}

				if (options != null) {
					Object value = null;
					StringList valueList = null;
					Item item = doc.findItem(this.getName());

					if (item != null)
						value = item.getValue();
					if (value != null)
						valueList = new StringList((String) value, ';');

					Iterator iter = options.getOptions().iterator();
					html.append("<SPAN style=\"FONT-SIZE: 9pt\">");
					String val = "";
					while (iter.hasNext()) {
						Option element = (Option) iter.next();

						if (valueList != null && element.getValue() != null) {
							if (valueList.indexOf(element.getValue()) >= 0) {
								if (this.getLayout() != null
										&& this.getLayout().equalsIgnoreCase(
												"vertical")) {
									val += element.getOption() + "<br>";
								} else {
									val += element.getOption() + ";";
								}
							}
						}
					}

					if (this.getLayout() != null
							&& this.getLayout().equalsIgnoreCase("vertical")) {
						val = val.substring(0, val.length() - 1);
					}
					html.append(val);
					return html.toString();
				}
			}
		}
		return "";
	}

	/**
	 * @param tmpltStr
	 * @return FormField
	 * @roseuid 41ECB66D0381
	 */
	public FormField init(String tmpltStr) {
		return null;
	}

	public String toTemplate() {
		StringBuffer template = new StringBuffer();
		template.append("<input type='radio'");
		template.append(" className='" + this.getClass().getName() + "'");
		template.append(" id='" + getId() + "'");
		template.append(" name='" + getName() + "'");
		template.append(" formid='" + getFormid() + "'");
		template.append(" discript='" + getDiscript() + "'");
		template.append(" hiddenScript='" + getHiddenScript() + "'");
		template.append(" hiddenPrintScript='" + getHiddenPrintScript() + "'");
		template.append(" refreshOnChanged='" + isRefreshOnChanged() + "'");
		template.append(" validateRule='" + getValidateRule() + "'");
		template.append(" valueScript='" + getValueScript() + "'");
		template.append(" optionScript='" + getOptionsScript() + "'");
		template.append("/>");
		return template.toString();

	}

	public String runOptionsScript(JavaScriptRunner runner, Document doc)
			throws Exception {
		Object result = null;
		StringBuffer html = new StringBuffer();
		int displayType = getDisplayType(runner, doc);
		if (displayType == PermissionType.HIDDEN) {
			return "(hidden)";
		} else {
			if (getOptionsScript() != null
					&& getOptionsScript().trim().length() > 0) {
				result = runner.run(StringUtil.dencodeHTML(getOptionsScript()));

				Options options = null;
				if (result != null && result instanceof String) {

					String[] strlst = ((String) result).split(";");
					options = new Options();
					for (int i = 0; i < strlst.length; i++) {
						options.add(strlst[i], strlst[i]);
					}
				} else if (result instanceof Options) {
					options = (Options) result;
				}
				if (options != null) {
					Object value = null;
					StringList valueList = null;
					Item item = doc.findItem(this.getName());

					if (item != null)
						value = item.getValue();
					if (value != null)
						valueList = new StringList((String) value, ';');

					if (doc != null) {
						Object defvalue = "";
						boolean isreadonly = false;

						Iterator iter = options.getOptions().iterator();
						while (iter.hasNext()) {
							Option element = (Option) iter.next();

							if ((this.getTextType() != null && this
									.getTextType().equalsIgnoreCase("READONLY"))
									|| (displayType == PermissionType.DISABLED)
									|| (displayType == PermissionType.READONLY)) {
								isreadonly = true;
							}

							html.append("<input type='radio' value=");
							html.append("\"");
							html.append(HtmlEncoder.encode(element.getValue()));
							html.append("\"");
							html.append(" name='");
							if (isreadonly) {
								html.append(this.getName() + "$forshow");
							} else {
								html.append(this.getName());
							}

							html.append("'");

							if (isRefreshOnChanged()) {
								html.append(" onclick='dy_refresh(this.name)'");
							}

							if (isreadonly) {
								html.append(" disabled ");
							}

							if (valueList != null && element.getValue() != null) {
								if (valueList.indexOf(element.getValue()) >= 0) {
									defvalue = element.getValue();
									html.append(" checked ");
								}
							} else {
								if (element.isDef()) {
									defvalue = element.getValue();
									html.append(" checked ");
								}
							}
							html.append(toOtherpropsHtml());
							html.append(" class='" + cssClass + "'");
							html.append("><font size=2>");
							html.append(element.getOption());
							html.append("</font></input>");

							if (this.getLayout() != null
									&& this.getLayout().equalsIgnoreCase(
											"vertical")) {
								html.append("<br>");
							}
						}
						if (isreadonly) {
							html
									.append("<input type='hidden' name='"
											+ getName() + "' value='"
											+ defvalue + "'>");
						}
					}
				}
			}
		}
		return html.toString();
	}

}

⌨️ 快捷键说明

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