📄 inputfield.java
字号:
//Source file:
//C:\\Java\\workspace\\SmartWeb3\\src\\com\\cyberway\\dynaform\\form\\ejb\\InputField.java
package cn.myapps.core.dynaform.form.ejb;
import java.text.SimpleDateFormat;
import java.util.Date;
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.HtmlEncoder;
import cn.myapps.util.ProcessFactory;
import cn.myapps.util.StringUtil;
public class InputField extends FormField {
/**
* @roseuid 41ECB66E012A
*/
protected static String cssClass = "input-cmd";
protected String dialogView = "";
protected boolean popToChoice;
protected boolean selectDate;
protected String validateLibs = "";
protected String fieldkeyevent = "";
public String getValidateLibs() {
return validateLibs;
}
public void setValidateLibs(String validateLibs) {
this.validateLibs = validateLibs;
}
public InputField() {
}
public String getFieldkeyevent() {
return fieldkeyevent;
}
public void setFieldkeyevent(String fieldkeyevent) {
this.fieldkeyevent = fieldkeyevent;
}
/**
* @return boolean
* @roseuid 41ECB66E013E
*/
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 41ECB66E0152
*/
public void store() {
}
/**
* @param doc
* @return java.lang.String
* @throws Exception
* @roseuid 41ECB66E015C
*/
public String toHtmlTxt(ParamsTable params, WebUser user,
JavaScriptRunner runner, Document doc) throws Exception {
StringBuffer html = new StringBuffer();
int displayType = getDisplayType(runner, doc);
// 添加Field
if (displayType == PermissionType.HIDDEN) {// 节点设置对应field隐藏
return "******";
} else {
if (getTextType() != null) {
if (getTextType().equalsIgnoreCase("text")) {
html.append("<input type='text' ");
} else if (getTextType().equalsIgnoreCase("readonly")) {
html.append("<input type='text' readonly");
} else if (getTextType().equalsIgnoreCase("hidden")) {
html.append("<input type='hidden'");
} else if (getTextType().equalsIgnoreCase("password")) {
html.append("<input type='password'");
} else {
html.append("<input type='text' ");
}
if (getFieldkeyevent() == null
|| getFieldkeyevent().trim().length() == 0
|| getFieldkeyevent().equalsIgnoreCase("Tabkey")) {
} else if (getFieldkeyevent().equalsIgnoreCase("Enterkey")) {
html.append(" onKeyDown='setEnter()' ");
}
html.append(" id='" + getId() + "'");
html.append(" name='" + getName() + "'");
if (isRefreshOnChanged()) {
html.append(" onchange='dy_refresh(this.name)'");
}
html.append(" class='" + cssClass + "'");
if (doc != null) {
Item item = doc.findItem(this.getName());
if (item != null && item.getValue() != null) {
Object value = item.getValue();
if (value instanceof Double) {
html.append(" value=\"" + item.getValue() + "\"");
} else if (value instanceof Date) {
Date d = (Date) value;
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd");
html.append(" value=\"" + format.format(d) + "\"");
} else {
html.append(" value=\""
+ HtmlEncoder.encode(item.getValue() + "")
+ "\"");
}
}
}
if (displayType == PermissionType.READONLY) {// 节点设置对应field只读或关闭
html.append(" readonly ");
} else if (displayType == PermissionType.DISABLED) {
html.append(" disabled ");
}
html.append(toOtherpropsHtml());
html.append(">");
if (getDialogView() != null
&& getDialogView().trim().length() > 0) {
if (displayType != PermissionType.DISABLED
&& displayType != PermissionType.READONLY) {// 设置对话框按钮field关闭
if (isPopToChoice()) {
html
.append("<input type='button' onclick='ViewHelper.convertValuesMapToPage("
+ "dy_getFormid(),\""
+ getDialogView()
+ "\",\""
+ getName()
+ "\",\""
+ user.getId()
+ "\",dy_getValuesMap(),function(text){showViewDialog(text,\""
+ getDialogView()
+ "\",\""
+ this.getName()
+ "\",\""
+ this.getClass().getName()
+ "\")})' value='{*[...]*}' ");
} else {
html
.append("<input type='button' onclick='ViewHelper.displayViewHtml("
+ "dy_getFormid(),\""
+ getDialogView()
+ "\",\""
+ getName()
+ "\",\""
+ user.getId()
+ "\",dy_getValuesMap(),function(text){src2(text,\"Choice\")})' value='{*[...]*}' ");
}
html.append("/>");
}
}
if (getFieldtype() != null) {
if (getFieldtype().equals(Item.VALUE_TYPE_DATE)
&& isSelectDate()
&& displayType != PermissionType.READONLY) { // 只读或不可选择日期时不生成
html
.append("<input type='button' value='...' onclick='"
+ getName()
+ ".value=selectDate("
+ getName() + ".value);");
if (isRefreshOnChanged()) {
html.append("dy_refresh(\"" + getName() + "\");");
}
html.append("'");
if (displayType == PermissionType.DISABLED) {// 设置日期field关闭
html.append(" disabled ");
}
html.append("/>");
}
}
}
}
return html.toString();
}
public String toPrintHtmlTxt(ParamsTable params, WebUser user,
JavaScriptRunner runner, Document doc) throws Exception {
StringBuffer html = new StringBuffer();
if (doc != null) {
if (getPrintDisplayType(runner, doc) != PermissionType.HIDDEN
&& !getTextType().equalsIgnoreCase("hidden")) {
Item item = doc.findItem(this.getName());
if (item != null && item.getValue() != null) {
Object value = item.getValue();
html.append("<DIV style=\"FONT-SIZE: 9pt\">");
if (value instanceof Double) {
html.append(item.getValue());
} else if (value instanceof Date) {
Date d = (Date) value;
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd");
html.append(format.format(d));
} else {
html.append(HtmlEncoder.encode(item.getValue() + ""));
}
html.append("</DIV>");
}
}
}
return html.toString();
}
public String toTemplate() {
StringBuffer template = new StringBuffer();
template.append("<input type='" + this.getTextType() + "'");
template.append(" class='" + this.cssClass + "'");
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(">");
return template.toString();
}
/**
* 重新计算
*
* @roseuid 41DB89D700F9
*/
public void recalculate(JavaScriptRunner runner, Document doc)
throws Exception {
// Debug.println("InputField.recalculate");
runValueScript(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) {
// Debug.println("JavaScript->"
// + StringUtil.dencodeHTML(getValueScript()));
result = runner.run(StringUtil.dencodeHTML(getValueScript()));
Item item = doc.findItem(this.getName());
item.setValue(result);
}
return result;
}
/**
* @hibernate.property column="dialogView"
*/
public String getDialogView() {
return dialogView;
}
public void setDialogView(String dialogView) {
this.dialogView = dialogView;
}
/**
* @hibernate.property column="popToChoice"
*/
public boolean isPopToChoice() {
return popToChoice;
}
public void setPopToChoice(boolean popToChoice) {
this.popToChoice = popToChoice;
}
/**
* @hibernate.property column="selectdate"
*/
public boolean isSelectDate() {
return selectDate;
}
public void setSelectDate(boolean selectDate) {
this.selectDate = selectDate;
}
}
/*
* FormField InputField.init(java.lang.String){ return null; }
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -