import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.fa.core.entity.PagedList;
import com.fa.core.utils.SpringUtil;
import com.fa.core.utils.StringUtil;
import com.fa.ibox.constant.ColumnType;
import com.fa.ibox.entity.Column;
import com.fa.ibox.entity.Site;
import com.fa.ibox.service.IColumnService;
import com.fa.ibox.service.ISiteService;
public class ColumnListTag extends ListTagBase<Column> {
/**
*
*/
private static final long serialVersionUID = 1L;
private Logger log = Logger.getLogger(this.getClass());
int columnId;
String columnName;
int siteId;
String siteName;
public int getColumnId() {
return columnId;
}
public void setColumnId(int columnId) {
this.columnId = columnId;
}
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
String columnCode;
public String getColumnCode() {
return columnCode;
}
public void setColumnCode(String columnCode) {
this.columnCode = columnCode;
}
public int getSiteId() {
return siteId;
}
public void setSiteId(int siteId) {
this.siteId = siteId;
}
public String getSiteName() {
return siteName;
}
public void setSiteName(String siteName) {
this.siteName = siteName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getEnsureChildLevel() {
return ensureChildLevel;
}
public void setEnsureChildLevel(int ensureChildLevel) {
this.ensureChildLevel = ensureChildLevel;
}
String type;
int ensureChildLevel = 100;
@SuppressWarnings("unchecked")
@Override
protected List<Column> getList() {
int cid = columnId, sid = siteId;
//1.检查上级
if(cid == 0 && (getParent() instanceof ColumnTag || getParent() instanceof ColumnListTag)){
Column parent = ((IBOXTagBase<Column>)getParent()).getElement();
if(parent != null){
cid = parent.getFdColuId();
}
}
//2.检查站点
if(sid > 0 || StringUtil.isEmpty(siteName) == false){
if(sid == 0){
Site cSite = getSiteService().getSiteInfo(siteName);
if(cSite != null){
sid = cSite.getFdSiteId();
}
}
}
//3.检查栏目名称
if(cid == 0 && StringUtil.isEmpty(columnName) == false){
Column parent = site.getColumn(columnName);
if(parent != null){
cid = parent.getFdColuId();
}
}
//4.检查栏目标识
if(cid == 0 && StringUtil.isEmpty(columnCode) == false){
Column parent = site.getColumn(columnCode);
if(parent != null){
cid = parent.getFdColuId();
}
}
//5.获取当前栏目id
if(sid == 0 && cid == 0 && StringUtil.isInteger(getParameter("cid"))){
cid = Integer.parseInt(getParameter("cid"));
}
ColumnType cType = ColumnType.UNKNOWN;
if(type != null){
cType = ColumnType.parse(type);
}
if(sid == 0 && cid == 0 && site != null){
sid = site.getFdSiteId();
}
List<Column> list = null;
IColumnService service = getColumnService();
if(cid > 0 && getPageId() == 1 && StringUtil.isEmpty(getWhere()) && StringUtil.isEmpty(getOrder())){
list = this.getColumnsFromCache(cid, cType, topCount);//直接读缓存以提高性能
//list = this.getColumnsFromCache(cid, cType, 0);//直接读缓存以提高性能
// //Add By yi 2011/6/13
// if(super.startPos > 0){
// list = list.subList(super.startPos, list.size());
// }
// if(list.size()>0)
// list = getTopList(list, topCount);
// //Add By yi 2011/6/13 End
}else{
PagedList<Column> pagedList = service.getColumnList(sid, cid, cType, getPageId(), getPageSize(), getWhere(), getOrder());
list = pagedList.getData();
List<Column> listCache = new ArrayList<Column>(list.size());
for(Column column : list){
if(site != null && column.getFdColuSiteId() == site.getFdSiteId().intValue()){
listCache.add(site.getColumn(column.getFdColuId()));
}else{
listCache.add(service.getColumnInfo(column.getFdColuId()));
}
}
list = listCache;
// //Add By yi 2011/6/13
// if(super.startPos > 0){
// list = list.subList(super.startPos, list.size());
// }
// //Add By yi 2011/6/13 End
if(this.topCount > 0 && list.size() > topCount){
list = service.getPagedList(1, topCount, list).getData();
}
}
Column me = null;
try{
if(list.size() == 0 && cid > 0){
me = service.getColumnInfo(cid);
int level = me.getLevel() == null?0:me.getLevel();
//这里getLevel返回空指针 , getLevel是什么意思??
if(me != null && level >= this.ensureChildLevel){
if(me.getParent() != null){
list = me.getParent().getChildren();
}else{
list = me.getSite().getColumns();
}
}
}
} catch (Exception e) {
e.printStackTrace();
log.info("cid>>>>" + cid + "; me>>>" + me + "; me.level>>>" + me.getLevel());
}
return list;
}
List<Column> getColumnsFromCache(int parentId, ColumnType type, int topCount){
List<Column> list = new ArrayList<Column>(0);
try {
Column parent = site.getColumn(parentId);
for(int i = 0; i < parent.getChildren().size(); i++){
if(type == ColumnType.UNKNOWN || parent.getChildren().get(i).getType() == type){
list.add(parent.getChildren().get(i));
if(list.size() >= topCount && topCount > 0){
break;
}
}
}
} catch (Exception e){
System.out.println("cid >>>>" + parentId);
}
return list;
}
// //Add By yi 2011/6/13
// List<Column> getTopList(List<Column> list, int topCount){
// if(topCount<=0)
// return list;
// List<Column> newList = new ArrayList<Column>(0);
// for(int i=0; i<topCount; i++){
// newList.add(list.get(i));
// if(newList.size()>=list.size())
// break;
// }
// return newList;
// }
IColumnService getColumnService(){
return (IColumnService)super.getEntityService();
}
ISiteService getSiteService(){
return (ISiteService)SpringUtil.getBean("siteService");
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.httpclient.util.DateUtil;
import com.fa.core.tag.SimpleTagBase;
import com.fa.core.utils.StringUtil;
public class PropertyTag extends SimpleTagBase {
String name;
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public int getLen() {
return len;
}
public void setLen(int len) {
this.len = len;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String format;
int len;
@Override
protected String getContent() {
String content = "";
if(this.getParent() instanceof IBOXTagBase<?>){
Object obj = ((IBOXTagBase<?>)getParent()).getElement();
if(obj != null){
try {
Object value = PropertyUtils.getProperty(obj, name);
if(value != null){
if(format != null && value instanceof Date){
//content = DateUtil.formatDate((Date)value, format);
content = new SimpleDateFormat(format).format(value);
}else{
content = value.toString();
if(len > 0){
content = StringUtil.left(content, len);
}
if("html".equals(format)){
content = StringUtil.getHtml(content);
}
}
}
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
}
return content;
}
public static void main(String[] args) {
//System.out.print(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
}
用法:
<h1>ibox:columnList 使用:</h1>
<br>
栏目名称:
<ibox:columnList columnId="16758">
<ibox:property name="fdColuName" /><br/>
</ibox:columnList>
具体的效果:
ibox:columnList 使用:
栏目名称: 公证动态
戒毒专区
人民监督员制度改革
依法治国
测试栏目
testv
二:自定义表单
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.ListOrderedMap;
import org.springframework.web.bind.ServletRequestUtils;
import com.fa.core.plugin.action.BaseAction;
import com.fa.core.plugin.pager.Page;
import com.fa.core.plugin.utils.PropertiesUtils;
import com.fa.core.plugin.utils.PublicUtil;
import com.fa.core.plugin.utils.StringUtil;
import com.fa.ibox.plugin.entity.FoField;
import com.fa.ibox.plugin.entity.FoForm;
import com.fa.ibox.plugin.entity.TfSite;
import com.fa.ibox.plugin.service.FoFieldService;
import com.fa.ibox.plugin.service.FoFormService;
import com.fa.ibox.plugin.service.TFSiteService;
import com.fa.ibox.plugin.util.DBUtil;
import com.fa.ibox.plugin.util.HtmlBean;
import com.fa.ibox.plugin.util.HtmlUtil;
import com.fa.ibox.plugin.util.OptionBean;
@SuppressWarnings("serial")
public class FoFormAction extends BaseAction {
private FoForm foForm;
private FoFormService foFormService;
private FoFieldService foFieldService;
private TFSiteService siteService;
private final String FORM_PERFIX = "FO_";
private TfSite site;
public TfSite getSite() {
return site;
}
public void setSite(TfSite site) {
this.site = site;
}
public FoForm getFoForm() {
return foForm;
}
public void setFoForm(FoForm foForm) {
this.foForm = foForm;
}
public FoFormService getFoFormService() {
return foFormService;
}
public void setFoFormService(FoFormService foFormService) {
this.foFormService = foFormService;
}
public void setFoFieldService(FoFieldService foFieldService) {
this.foFieldService = foFieldService;
}
public void setSiteService(TFSiteService siteService) {
this.siteService = siteService;
}
@SuppressWarnings({})
public String doList() {
try {
// List siteList = siteService.queryAllSite();
// int siteId = ServletRequestUtils.getIntParameter(getRequest(),
// "siteid", 0);
int pageNo = ServletRequestUtils.getIntParameter(getRequest(), "pageNo", 1);
Page page = foFormService.pagedQueryForm(pageNo);
getRequest().setAttribute("page", page);
// this.getRequest().setAttribute("siteList", siteList);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
@SuppressWarnings("rawtypes")
public String doPageQueryData() {
try {
//List siteList = siteService.queryAllSite();
int pageNo = ServletRequestUtils.getIntParameter(getRequest(),
"pageNo", 1);
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
Page page = foFormService.pageQueryData(formId, pageNo);
getRequest().setAttribute("page", page);
//this.getRequest().setAttribute("siteList", siteList);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
public String doDisplayRecord() {
List<String> title = new ArrayList<String>();
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
long fdId = ServletRequestUtils.getLongParameter(getRequest(), "fdId",
-1);
ListOrderedMap record = foFormService.getAFormRecord(formId, fdId,
title);
getRequest().setAttribute("title", title);
getRequest().setAttribute("record", record);
return SUCCESS;
}
public String doUpdateData() {
// 处理状态
String status = ServletRequestUtils.getStringParameter(getRequest(),
"status", "未处理");
// 显示在网站
int show = ServletRequestUtils.getIntParameter(getRequest(), "show", 0);
// 回复内容
String reply = ServletRequestUtils.getStringParameter(getRequest(),
"reply", "");
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
long fdId = ServletRequestUtils.getLongParameter(getRequest(), "fdId",
-1);
foFormService.updateRecord(status, reply, show, formId, fdId);
return SUCCESS;
}
public String doSave() throws Exception {
try {
if (foForm.getFdformislimitip() == null) {
foForm.setFdformislimitip(0L);
}
if (foForm.getFdformislimitcookie() == null) {
foForm.setFdformislimitcookie(0L);
}
if (PublicUtil.checkEmptyString(foForm.getFdformdescription())) {
foForm.setFdformdescription(" ");
}
if (PublicUtil.checkEmptyString(foForm.getFdformgourl())) {
foForm.setFdformgourl(" ");
}
if (PublicUtil.checkEmptyString(foForm.getFdformresult())) {
foForm.setFdformresult(" ");
}
// 如果是修改
if (PublicUtil.checkBigerThanZero(foForm.getFdformid())) {
FoForm foFormDb = (FoForm) foFormService.getById(foForm
.getFdformid());
foForm.setFdformcreateat(foFormDb.getFdformcreateat());
foForm.setFdformcountsum(foFormDb.getFdformcountsum());
}
// 如果是新增
if (!PublicUtil.checkBigerThanZero(foForm.getFdformid())) {
foForm.setFdformtable(FORM_PERFIX + foForm.getFdformtable());
foForm.setFdformid(DBUtil.getTableNextID("FO_FORM"));
foForm.setFdformcreateat(new Date());
foForm.setFdformcountsum(0L);
foFormService.createBaseTable(foForm.getFdformtable());
}
foFormService.saveOrUpdate(foForm);
} catch (Exception e) {
e.printStackTrace();
log.info("保存失败!" + e.getMessage());
alertAndBack("保存失败!" + e.getMessage());
return null;
}
return SUCCESS;
}
public String doDelete() {
try {
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
List<FoField> list = foFieldService.getFieldsByFormId(formId);
if (list.size() > 0) {
this.successAndGo("删除失败,请先删除表单下的字段", "doList.do");
return null;
}
foFormService.dropTable(formId);
this.successAndGo("删除成功", "doList.do");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public String doEdit() {
if (foForm != null
&& PublicUtil.checkBigerThanZero(foForm.getFdformid())) {
foForm = (FoForm) foFormService.getById(foForm.getFdformid());
}
return SUCCESS;
}
public String doIsExistTableName() {
String tableName = ServletRequestUtils.getStringParameter(getRequest(),
"tableName", "");
tableName = StringUtil.to8859Utf(tableName);
boolean b = foFormService.isExistTableName(FORM_PERFIX + tableName);
this.renderText(this.getResponse(), b + "");
return null;
}
public String doDeleteData() {
try {
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
String[] fdId = super.getParameter("ids").toString().split(",");
foFormService.deleteData(formId, fdId);
} catch (Exception e) {
e.printStackTrace();
alertAndBack("删除失败!" + e.getMessage());
}
return SUCCESS;
}
@SuppressWarnings("rawtypes")
public String doSaveFormData() throws Exception {
Map fieldMap = this.getRequest().getParameterMap();
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"form$formId", -1);
if (formId == -1) {
log.error("提交数据有误!");
this.renderText(this.getResponse(), "0");
return null;
}
String ip = PublicUtil.getClientIp(getRequest());
long userId = 8888;
String message = "";
String url = "";
// 根据id找form
FoForm form = (FoForm) foFormService.getById(formId);
if (form != null) {
message = form.getFdformresult().trim();
url = form.getFdformgourl().trim();
}
try {
foFormService.saveFormData(fieldMap, formId, ip, userId);
} catch (Exception e) {
e.printStackTrace();
log.error("提交数据数据失败!");
this.renderText(this.getResponse(), "2");
return null;
}
if (!"".equals(message.trim()) && !"".equals(url.trim())) {
this.successAndGo(message, url);
} else if (!"".equals(message) && "".equals(url)) {
this.renderText(this.getResponse(), message);
} else if ("".equals(message) && !"".equals(url)) {
this.go(url);
}
return null;
}
public String doGetDataFromPattern() throws Exception {
try {
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
if (formId == -1) {
log.error("该 自定义表不存在!请输入正确的自定义表名称!");
return null;
}
int pageSize = ServletRequestUtils.getIntParameter(getRequest(),
"pageSize", Page.getDEFAULT_PAGE_SIZE());
;
int pageNo = ServletRequestUtils.getIntParameter(getRequest(),
"pageNo", 1);
String where = ServletRequestUtils.getStringParameter(getRequest(),
"where", "");
;
int showReply = ServletRequestUtils.getIntParameter(getRequest(),
"showReply", 0);
int topCount = ServletRequestUtils.getIntParameter(getRequest(),
"topCount", 0);
String pattern = ServletRequestUtils.getStringParameter(
getRequest(), "pattern", "");
pattern = URLDecoder.decode(pattern, "utf-8");
String result = foFormService.pageQueryDataFront(formId, pageSize,
pageNo, pattern, where, showReply, topCount);
log.info(result);
this.renderText(this.getResponse(), result);
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
static Map<String, FoField> map = new HashMap<String, FoField>();
static Map<String, String> tableMap = new HashMap<String, String>();
public String doGetFormByTable() {
String tableName = getParameter("tableName");
String fieldName = getParameter("fieldName");
if (tableName != null && !"".equals(tableName)) {
if (!tableMap.containsKey(tableName)) {
// map = init(tableName);
map.putAll(init(tableName));
tableMap.put(tableName, tableName);
}
}
System.out.print("map.size()=" + map.size() + "\r\n");
String str = getFieldHtml(fieldName);
if (str != null)
this.renderText(this.getResponse(), str);
return null;
}
@SuppressWarnings("unused")
public Map<String, FoField> init(String tableName) {
List<FoField> fieldList = foFieldService
.getFoFieldByTableName(tableName);
FoForm form = foFormService.queryByTableName(tableName);
return listToMap(fieldList);
}
public Map<String, FoField> listToMap(List<FoField> list) {
Map<String, FoField> map = new HashMap<String, FoField>();
for (int i = 0; i < list.size(); i++) {
FoField f = list.get(i);
map.put(f.getFdfielname(), f);
}
return map;
}
public String getFieldHtml(String fieldname) {
StringBuffer s = new StringBuffer();
if (map.size() > 0) {
FoField foField = map.get(fieldname);
if (foField != null) {
HtmlBean bean = new HtmlBean();
bean.setId(foField.getFdfielid() + "");
bean.setName(foField.getFdfielname());
bean.setValue(foField.getFdfieldefaultvalue());
bean.setControlType(foField.getFdfielctrltype() + "");
bean.setLabel(foField.getFdfielname2());
bean.setOther(foField.getFdfielother() + "");
bean.setMaxlength(foField.getFdfielmaxlength() + "");
bean.setCtrlValiType(foField.getFdfielctrlvalitype());
bean.setErrMsg(foField.getFdfielctrlvalimsg());
bean.setTip(foField.getFdfieltip());
bean.setRequired(foField.getFdfielrequire() + "");
// 1单行文本 2多行文本 3HTML 4下拉框 5单选 6多选 7是/否(复选框) 8图片 9文件 10比例
// 11验证码
if (foField.getFdfielctrltype() == 1) {// 1单行文本
bean.setStyle(foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "px;");
} else if (foField.getFdfielctrltype() == 2) {// 2多行文本
String style = foField.getFdfielwidth() == 0 ? ""
: "width:" + foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 3) {// 3HTML
String style = foField.getFdfielwidth() == 0 ? ""
: "width:" + foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 4) {// 4下拉框
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 5) {// 5单选
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 6) {// 6多选
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 7) {// 7是/否(复选框)
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 8) {// 8图片
String style = foField.getFdfielwidth() == 0 ? ""
: "width:" + foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 9) {// 9文件
String style = foField.getFdfielwidth() == 0 ? ""
: "width:" + foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 10) {// 10比例
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 11) {// 11验证码
String style = foField.getFdfielwidth() == 0 ? ""
: "width:" + foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
}
s = HtmlUtil.createHtml(bean);
return s.toString();
}
}
return null;
}
public List<OptionBean> create(FoField foField) {
String parameter = foField.getFdfielparameter();
String[] params = null;
if (parameter.length() > 0) {
params = parameter.split("&");
}
List<OptionBean> list = new ArrayList<OptionBean>();
OptionBean opBean = null;
if (params != null)
for (int i = 0; i < params.length; i++) {
opBean = new OptionBean();
String str = params[i].toString();
if (str.indexOf("=") != -1) {
opBean.setValue(str.substring(0, str.indexOf("=")));
opBean.setName(str.substring(str.indexOf("=") + 1));
} else {
opBean.setValue(str);
opBean.setName(str);
}
list.add(opBean);
}
return list;
}
public String doGetForm() {
String tableName = getParameter("tableName");
FoForm form = foFormService.queryByTableName(tableName);
if (form != null) {
JSONObject json = JSONObject.fromObject(form);
this.renderJson(this.getResponse(), json.toString());
}
return null;
}
/**
* 导出表单数据为xls文件
*/
@SuppressWarnings("deprecation")
public String doExportXLSFile() {
String fileName = "";
Properties properties = PropertiesUtils
.getPropertiesFile("file.properties");
try {
long formId = ServletRequestUtils.getLongParameter(getRequest(),
"formId", -1);
fileName = properties.getProperty("tempDataPath")
+ "/export/tsjy.xls";
foFormService.expData(formId, getRequest().getRealPath("")
+ fileName);
} catch (Exception e) {
e.printStackTrace();
fileName = "";
}
this.renderText(this.getResponse(), fileName);
return null;
}
//有个随机串rd没有setter方法,struts2报错,解决方法Error setting expression 'rd' with value ['0.29432497590392936', ] - [unknown location]
public void setRd(String rd) {
//no meaning
}
public void setFormId(String formId) {
//no meaning
}
}
紧接着上一篇文章:http://blog.youkuaiyun.com/wuqilianga/article/details/79037230
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import com.fa.ibox.plugin.entity.FoField;
public class FormTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 5728041127347992678L;
private String tablename = "";
private int generatesubmit = 1;
private String message = "";
private String target = "_self";
private String remark = "";
private static String action = "/plugin/selfForm/doSaveFormData.do";
List<FoField> fieldList = new ArrayList<FoField>();
public static Map<String, FoField> map = new HashMap<String, FoField>();
StringBuffer result = new StringBuffer();
@Override
public int doStartTag() throws JspException {
StringBuffer sb = new StringBuffer();
sb.append("<script type=\"text/javascript\" src=\"/plugin/js/validator.js\"></script>");
sb.append("<script type=\"text/javascript\">");
sb.append("function getFieldHtml(tableName,fieldName){");
sb.append(String
.format(" var link = \"/plugin/selfForm/doGetFormByTable.do?tableName=%1$s&fieldName=\"+fieldName;",
tablename));
sb.append(" $.ajax(");
sb.append(" {");
sb.append(" type: 'POST',");
sb.append(" url: link,");
sb.append(" async: false,");
sb.append(" success: function(htm) {");
// sb.append(String.format(" $(\"#form_%1$s\").append(htm);",tablename));
sb.append(" $(\"#\"+fieldName).html(htm);");
sb.append(" }");
sb.append(" });");
sb.append("}");
sb.append("</script>");
sb.append(String.format(
"<form id=\"form_%1$s\" name=\"form$%1$s\" method=\"post\" ",
this.tablename));
sb.append(String.format(" action=\"%1$s\" ", action));
if (target != null && !"".equals(target)) {
sb.append(String.format(" target=\"%1$s\" ", this.target));
}
sb.append(">");
sb.append("<input id=\"form$formId\" type=\"hidden\" name=\"form$formId\" value=\"\"/>");
if ("".equals(this.message)) {
sb.append(String
.format("<input type=\"hidden\" name=\"form$message\" value=\"%1$s\"/>",
""));
} else {
sb.append(String
.format("<input type=\"hidden\" name=\"form$message\" value=\"%1$s\"/>",
this.message));
}
if ("".equals(this.remark)) {
sb.append(String.format("<div>%1$s</div>", ""));
} else {
sb.append(String.format("<div>%1$s</div>", this.remark));
}
renderHtml(sb);
return EVAL_BODY_INCLUDE;
}
@Override
public int doEndTag() throws JspException {
StringBuffer sb = new StringBuffer();
if (generatesubmit == 1) {
sb.append("<br/><input type=\"submit\" value=\"提交\" />");
}
sb.append("</form>");
sb.append("<script type=\"text/javascript\">");
sb.append(String
.format(" var linkForm = \"/plugin/selfForm/doGetForm.do?tableName=%1$s\";",
tablename));
sb.append(" $.ajax(");
sb.append(" {");
sb.append(" type: 'POST',");
sb.append(" url: linkForm,");
sb.append(" async: false,");
sb.append(" dataType : 'json',");
sb.append(" success: function(data) {");
sb.append(" $(\"#form$formId\").val(data.fdformid);");
sb.append(" }");
sb.append(" });");
sb.append("</script>");
sb.append(String
.format("<script type=\"text/javascript\">Validator.BoundControls(document.getElementById(\"form_%1$s\"));</script>",
tablename));
renderHtml(sb);
return EVAL_PAGE;
}
public void addHtml(Object arg) {
result.append(arg);
}
public void renderHtml(Object arg) {
try {
this.pageContext.getOut().write(arg.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
public void setTablename(String tablename) {
this.tablename = tablename;
}
public void setGeneratesubmit(int generatesubmit) {
this.generatesubmit = generatesubmit;
}
public void setMessage(String message) {
this.message = message;
}
public void setTarget(String target) {
this.target = target;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getTablename() {
return tablename;
}
public int getGeneratesubmit() {
return generatesubmit;
}
public String getMessage() {
return message;
}
public String getTarget() {
return target;
}
public String getRemark() {
return remark;
}
}
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;
import com.fa.ibox.plugin.entity.FoField;
public class FieldTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = -1790932532718193274L;
private String fieldname;
FoField foField = null;
@Override
public int doStartTag() throws JspException {
Tag tag = findAncestorWithClass(this, FormTag.class);
FormTag parent = (FormTag) tag;
String tableName = parent.getTablename();
StringBuffer sb = new StringBuffer();
sb.append("<script type=\"text/javascript\">");
sb.append("getFieldHtml(\"" + tableName + "\",\"" + fieldname + "\");");
sb.append("</script>");
try {
this.pageContext.getOut().write(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public void setFieldname(String fieldname) {
this.fieldname = fieldname;
}
}
import java.util.ArrayList;
import java.util.List;
import com.fa.core.plugin.dao.SpringBeanTools;
import com.fa.core.plugin.tag.SimpleTagBase;
import com.fa.ibox.plugin.entity.FoField;
import com.fa.ibox.plugin.service.FoFieldService;
import com.fa.ibox.plugin.util.HtmlBean;
import com.fa.ibox.plugin.util.HtmlUtil;
import com.fa.ibox.plugin.util.OptionBean;
public class ControlTag extends SimpleTagBase {
private long formid;
private String fieldName;
FoField foField = new FoField();
@Override
protected String getContent() {
getFieldType();
HtmlBean bean = new HtmlBean();
bean.setId(foField.getFdfielid() + "");
bean.setName(foField.getFdfielname());
bean.setValue(foField.getFdfieldefaultvalue());
bean.setControlType(foField.getFdfielctrltype() + "");
bean.setLabel(foField.getFdfielname2());
bean.setOther(foField.getFdfielother() + "");
bean.setMaxlength(foField.getFdfielmaxlength() + "");
bean.setCtrlValiType(foField.getFdfielctrlvalitype());
bean.setErrMsg(foField.getFdfielctrlvalimsg());
bean.setTip(foField.getFdfieltip());
bean.setRequired(foField.getFdfielrequire() + "");
// 1单行文本 2多行文本 3HTML 4下拉框 5单选 6多选 7是/否(复选框) 8图片 9文件 10比例 11验证码
if (foField.getFdfielctrltype() == 1) {// 1单行文本
bean.setStyle(foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "\"px;");
} else if (foField.getFdfielctrltype() == 2) {// 2多行文本
String style = foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 3) {// 3HTML
String style = foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 4) {// 4下拉框
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 5) {// 5单选
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 6) {// 6多选
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 7) {// 7是/否(复选框)
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 8) {// 8图片
String style = foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 9) {// 9文件
String style = foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
} else if (foField.getFdfielctrltype() == 10) {// 10比例
List<OptionBean> list = create(foField);
bean.setList(list);
} else if (foField.getFdfielctrltype() == 11) {// 11验证码
String style = foField.getFdfielwidth() == 0 ? "" : "width:"
+ foField.getFdfielwidth() + "px;";
style += foField.getFdfielheight() == 0 ? "" : "height:"
+ foField.getFdfielheight() + "px;";
bean.setStyle(style);
}
StringBuffer s = HtmlUtil.createHtml(bean);
return s.toString();
}
public List<OptionBean> create(FoField foField) {
String parameter = foField.getFdfielparameter();
String[] params = null;
if (parameter.length() > 0) {
params = parameter.split("&");
}
List<OptionBean> list = new ArrayList<OptionBean>();
OptionBean opBean = null;
for (int i = 0; i < params.length; i++) {
opBean = new OptionBean();
String str = params[i].toString();
if (str.indexOf("=") != -1) {
opBean.setValue(str.substring(0, str.indexOf("=")));
opBean.setName(str.substring(str.indexOf("=") + 1));
} else {
opBean.setValue(str);
opBean.setName(str);
}
list.add(opBean);
}
return list;
}
public void getFieldType() {
FoFieldService foFieldService = (FoFieldService) SpringBeanTools
.getSpringBean("foFieldService");
List<FoField> list = foFieldService.getFoFieldByFormIdAndName(formid,
fieldName);
if (list.size() > 0) {
foField = list.get(0);
}
// List<FoField> list = map.get(formid);
// if(list == null || list.size() == 0){
// map = foFieldService.queryFields(formid);
// list = map.get(formid);
// }
//
// for(int i=0;i<list.size();i++){
// FoField field = list.get(i);
// if(fieldName.equals(field.getFdfielname())){
// foField = field;
// break;
// }
// }
}
public void setFormid(long formid) {
this.formid = formid;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
}
1. 自定义表单置标ibox:form,需要配合ibox:formData等使用
语法:
<ibox:form [tablename=创建的表单名称] [ generatesubmit=是否自动生成”提交”按
钮 ] [ message=表单提交后提示信息] [target=提交窗口默认样式] [ remark=表单标题]>
</ibox:form>
!!注意,这里部分属性,在代码开发者,并没有完全依照驼峰命名法,请依照之使用
置标属性说明
属性 | 描述 | 类型 | 取值 | 值说明 |
|
|
|
|
|
tablename | 你所创建的表 | 字符 |
| 在所有的表单列 |
| 单名称 |
|
| 表中,其名称唯 |
|
|
|
| 一。 |
|
|
|
|
|
generatesubmit | 是否自动生成” | 数字 | 0 | 否 |
| 提交”按钮 |
|
|
|
|
|
|
|
|
|
|
| 1 | 是(默认) |
|
|
|
|
|
message | 点击了提交按 | 字符串 |
|
|
| 钮后的 |
|
|
|
|
|
|
|
|
target | 提交窗口 | 字符串 |
| 默认是"_self", |
|
|
|
| 跟 a 的提交属性 |
|
|
|
| 一致 |
|
|
|
|
|
remark | 表单标题,显示 | 字符串 |
| 一方面是方便在 |
| 在前台表单列 |
|
| 模板里面辨认, |
| 表上。 |
|
| 另一方面的作用 |
|
|
|
| 是它会生成在静 |
|
|
|
| 态文件的 html |
|
|
|
| 文件中 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
应用举例:
1)第一种用法使用:fdf1 - fdf11为自定义属性,分别代表了控件类型:
1单行文本
2多汗文本
3 HTML
4下拉框
5单选
6多选
7是/否(复选框)
8图片
9文件
10比例
11验证码
注意点:必须引入jq的库才能正常工作标签<ibox:div>必须由属性为id的div包裹着,必须操作js/jq相关操作方能显示验证码图像
<scripttype="text/javascript"src="js/jquery.js"></script>
<h1>ibox:form使用:</h1>
<br>
<ibox:formtablename="FO_DS_aofei"generatesubmit="1"
message="感谢您的意见,我们会尽快联系您的!">
<divid="fdf1"><ibox:formfieldfieldname="fdf1"/></div>
<divid="fdf2"><ibox:formfieldfieldname="fdf2"/></div>
<divid="fdf3"><ibox:formfieldfieldname="fdf3"/></div>
<divid="fdf4"><ibox:formfieldfieldname="fdf4"/></div>
<divid="fdf5"><ibox:formfieldfieldname="fdf5"/></div>
<divid="fdf6"><ibox:formfieldfieldname="fdf6"/></div>
<divid="fdf7"><ibox:formfieldfieldname="fdf7"/></div>
<divid="fdf8"><ibox:formfieldfieldname="fdf8"/></div>
<divid="fdf9"><ibox:formfieldfieldname="fdf9"/></div>
<divid="fdf10"><ibox:formfieldfieldname="fdf11"/></div>
<divid="fdf11"><ibox:formfieldfieldname="fdf11"/></div>
</ibox:form>
<scripttype="text/javascript">
$(function() {
//验证码
$('#imgValcode').attr("src","https://www.baidu.com/handsomboy.png");
$('#imgValcode').css({
"display":"block"
});
});
</script>
2)第二种用法使用:fdf1 - fdf11为自定义属性,分别代表了控件类型:
1单行文本
2多汗文本
3 HTML
4下拉框
5单选
6多选
7是/否(复选框)
8图片
9文件
10比例
11验证码
注意点:必须操作js/jq相关操作方能显示验证码图像
<h1>ibox:ctl使用:</h1>
<br>
<ibox:formtablename="FO_DS_aofei"generatesubmit="1"
message="感谢您的意见,我们会尽快联系您的!">
<divid="fdf1"><ibox:ctlfieldName="fdf1"formid="28"/></div>
<divid="fdf2"><ibox:ctl fieldName="fdf2"formid="28"/></div>
<divid="fdf3"><ibox:ctl fieldName="fdf3"formid="28"/></div>
<divid="fdf4"><ibox:ctl fieldName="fdf4"formid="28"/></div>
<divid="fdf5"><ibox:ctl fieldName="fdf5"formid="28"/></div>
<divid="fdf6"><ibox:ctl fieldName="fdf6"formid="28"/></div>
<divid="fdf7"><ibox:ctl fieldName="fdf7"formid="28"/></div>
<divid="fdf8"><ibox:ctl fieldName="fdf8"formid="28"/></div>
<divid="fdf9"><ibox:ctl fieldName="fdf9"formid="28"/></div>
<divid="fdf10"><ibox:ctl fieldName="fdf11"formid="28"/></div>
<divid="fdf11"><ibox:ctl fieldName="fdf11"formid="28"/></div>
</ibox:form>
<scripttype="text/javascript">
$(function() {
//验证码
$('#imgValcode').attr("src","https://www.baidu.com/handsomboy.png");
$('#imgValcode').css({
"display":"block"
});
});
</script>
</body>
</html>