?? webform.java
字號(hào):
package com.wlpava.utils;
import java.util.Map;
import org.apache.log4j.Logger;
import com.wlpava.utils.CommUtil;
/**
*
* <p>
* Title:Web表單類
* </p>
* <p>
* Description: WebForm 負(fù)責(zé)封裝用于用戶端顯示的數(shù)據(jù),并根據(jù)頁面組件事件觸法相應(yīng)的事件
* 讀取Form中的數(shù)據(jù)直接使用form.get("屬性名")即可 設(shè)置form的屬性值使用form.set("屬性名",值)即可
* form負(fù)責(zé)封裝了用于模板文件中顯示的變量名。通過IWebAction添加變量值 使用方法:form.addResult("變量名",值)
* <p>
* Copyright: Copyright (c) 2006
* </p>
* <p>
* Company: www.easyjf.com
* </p>
*
* @author 蔡世友
* @version 1.0
*/
public class WebForm {
private Map textElement;
private Map fileElement;
private Map property;
private FormConfig formConfig;
private Map easyJWebResult;
private static final Logger logger = (Logger) Logger.getLogger(WebForm.class);
public WebForm() {
}
public boolean validate() {
if (formConfig != null && (formConfig.getServerValidate().equals("true") || formConfig.getServerValidate().equals("yes"))) {
return doValidate();
}
else return true;
}
// 把form表單的數(shù)據(jù)轉(zhuǎn)換成Object對(duì)象
public Object toPo(Object obj) {
CommUtil.Map2Obj(this.getTextElement(), obj);
return obj;
}
// 把form表單中的數(shù)據(jù)轉(zhuǎn)換成classType類對(duì)象
public Object toPo(Class classType) {
Object obj = null;
try {
obj = classType.newInstance();
CommUtil.Map2Obj(this.getTextElement(), obj);
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
// PO對(duì)象中的數(shù)據(jù)存放到FORM對(duì)象中
public void addPo(Object obj) {
if (obj != null)
CommUtil.Obj2Map(obj, this.getTextElement());
}
/**
* 通過配置文件中的檢驗(yàn)設(shè)置分別校驗(yàn)表單數(shù)據(jù)
*
* @return
*/
protected boolean doValidate() {
return true;
}
public Object get(String name) {// throws NoPropertyException
// System.out.println("返回值嗎?"+((this.getClass()!=WebForm.class)&&(!property.containsKey(name))));
if ((this.getClass() != WebForm.class) && (!property.containsKey(name)))
return null;
// throw new NoPropertyException("the property '"+name+"' is not
// exist!");
// System.out.println("返回值嗎?"+fileElement.size());
if (textElement.containsKey(name))
return textElement.get(name);
else
return fileElement.get(name);
// throw new NoPropertyException("the property '"+name+"' is not
// exist!");
}
public void set(String key, Object value) {
if (textElement.containsKey(key))
textElement.put(key, value);
else if (fileElement.containsKey(key))
fileElement.put(key, value);
else
logger.error("表單中沒有該屬性!");
}
public Map getFileElement() {
return fileElement;
}
public void setFileElement(Map fileElement) {
this.fileElement = fileElement;
}
public Map getTextElement() {
return textElement;
}
public void setTextElement(Map textElement) {
this.textElement = textElement;
}
public Map getProperty() {
return property;
}
public void setProperty(Map property) {
this.property = property;
}
public FormConfig getFormConfig() {
return formConfig;
}
public void setFormConfig(FormConfig formConfig) {
this.formConfig = formConfig;
}
public Map getEasyJWebResult() {
return easyJWebResult;
}
public void setEasyJWebResult(Map easyJWebResult) {
this.easyJWebResult = easyJWebResult;
}
/**
* 設(shè)置模板文件中的變量值
*
* @param key
* @param value
*/
public void addResult(String key, Object value) {
if (!key.equals("easyJWebResult"))
easyJWebResult.put(key, value);
else
logger.error("企圖使用EasyJWeb系統(tǒng)關(guān)鍵字easyJWebResult保存數(shù)據(jù)失敗");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -