public class FormInputUtil { /** * 获取表单中的InputText * * @param name * @param rs * @return */ public static String getFormInput(String name, ResultSet rs) { StringBuffer buffer = new StringBuffer(); try { buffer.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name) .append("\" size=\"57\" style=\"height:22; border:0; vertical-align: middle; line-height:22px;\" value=\"") .append(DaoUtil.nullToString(rs.getString(name))).append("\" />"); } catch (SQLException e) { e.printStackTrace(); } return buffer.toString(); } /** * 获取表单中的InputText * * @param name * @param rs * @return */ public static String getFormInput1(String name, String value) { StringBuffer buffer = new StringBuffer(); buffer.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name) .append("\" size=\"57\" style=\"height:22; border:0; vertical-align: middle; line-height:22px;\" value=\"") .append(value).append("\" />"); return buffer.toString(); } /** * 获取表单中Input中的时间 * * @param name * @param rs * @return */ public static String getFormInputTime(String name, ResultSet rs) { StringBuffer buffer = new StringBuffer(); try { buffer.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name) .append("\" class=\"Wdate\" size=\"57\" style=\"height:22; border:0; vertical-align: middle; line-height:22px;\"" + " onfocus=\"WdatePicker({skin:‘whyGreen‘})\" value=\"").append(DaoUtil.nullToString(rs.getString(name))).append("\" />"); } catch (SQLException e) { e.printStackTrace(); } return buffer.toString(); } /** * input 隐藏 * @param name * @param rs * @return */ public static String getFormInputHidden(String name, ResultSet rs) { StringBuffer buffer = new StringBuffer(); try { buffer.append("<input type=\"hidden\" name=\"").append(name).append("\" value=\""+DaoUtil.nullToString(rs.getString(name))+"\"") .append("/>"+DaoUtil.nullToString(rs.getString(name))); } catch (SQLException e) { e.printStackTrace(); } return buffer.toString(); } /** * input 的值为空 * @param name * @param type * @return */ public static String getFormInputNullValue(String name, String type) { String html = "<input type=\""+type+"\" id=\""+name+"\" name=\""+name+"\" size=\"57\" " + "style=\"height:22; border:0; vertical-align: middle; line-height:22px;\" value=\"\" />"; if(type.equals("time")){ html = "<input type=\"text\" id=\""+name+"\" name=\""+name+"\" class=\"Wdate\" size=\"57\" style=\"height:22;" + " border:0; vertical-align: middle; line-height:22px;\" onfocus=\"WdatePicker({skin:‘whyGreen‘})\" value=\"\" />"; } return html; } /** * 表单input * @param name * @param ht * @param type input类型 * @param flag 能否编辑 * @return */ public static String getEditInput(String name, Hashtable ht, String type, boolean flag){ StringBuffer s = new StringBuffer(); if(type.equals("text") || type.equals("date") || type.equals("select-one") || type.equals("number") || type.equals("phone") || type.equals("date_year") || type.equals("money") || type.equals("select-one-other") || type.equals("text1")){ if(flag){ // 文本框 if(type.equals("text")){ s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"") .append(DaoUtil.nullToString(ht.get(name))).append("\" style=\"border:#999 1px solid;height: 22px;width: 164px;vertical-align: middle;line-height: 22px;\" />"); }else if(type.equals("text1")){ s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"") .append(DaoUtil.nullToString(ht.get(name))).append("\" class=‘manage_text‘ />"); // 时间 2012-01-01 }else if(type.equals("date")){ String minDate = DaoUtil.nullToString(DaoUtil.HASHTAGS.get("DEFAULT_MINDATE")).equals("")?"":",minDate:‘"+DaoUtil.HASHTAGS.get("DEFAULT_MINDATE")+"‘"; s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"").append(DaoUtil.nullToString(ht.get(name))) .append("\" class=\"Wdate\" style=\"height: 22px;width: 164px;\" onClick=\"WdatePicker({readOnly:true,dateFmt:‘yyyy-MM-dd‘,isShowClear:false"+minDate+"})\" />"); DaoUtil.HASHTAGS.remove("DEFAULT_MINDATE"); // 时间 2012 }else if(type.equals("date_year")){ s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"").append(DaoUtil.nullToString(ht.get(name))) .append("\" class=\"Wdate\" style=\"height: 22px;width: 164px;\" onClick=\"WdatePicker({dateFmt:‘yyyy‘,readOnly:true,isShowClear:false})\" />"); // 下拉框 }else if(type.equals("select-one")){ s.append("<select id=\"").append(name).append("\" name=\"") .append(name).append("\" style=\"width:164px;border:#999 1px solid;\">").append("<option value=\"\" selected=\"selected\">请选择...</option>"); String[] arr = DaoUtil.HASHTAGS.get("select-"+name).toString().split(","); for(int i=0;i<arr.length;i++){ s.append("<option value=\"").append(arr[i]).append("\" ").append(DaoUtil.nullToString(ht.get(name)).equals(arr[i])? "selected":"").append(">").append(arr[i]).append("</option>"); } DaoUtil.HASHTAGS.remove("select-"+name); s.append("</select>"); // 下拉框2 }else if(type.equals("select-one-other")){ s.append("<select id=\"").append(name).append("\" name=\"") .append(name).append("\" style=\"width:164px;border:#999 1px solid;\">").append("<option value=\"\" selected=\"selected\">请选择...</option>"); String[] arr = DaoUtil.HASHTAGS.get("select-other-"+name).toString().split("\\|"); String[] key = arr[0].split(","); String[] value = arr[1].split(","); for(int i=0;i<value.length;i++){ s.append("<option value=\"").append(value[i]).append("\" ").append(DaoUtil.nullToString(ht.get(name)).equals(value[i])? "selected":"").append(">").append(key[i]).append("</option>"); } DaoUtil.HASHTAGS.remove("select-other-"+name); s.append("</select>"); // 数字 0-9 }else if(type.equals("number")){ s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"") .append(DaoUtil.nullToString(ht.get(name))).append("\" style=\"border:#999 1px solid;height: 22px;width: 164px;\"") .append(" onKeyPress=\"if(event.keyCode<48||event.keyCode>57)event.returnValue=false;\" />"); // 电话号码 0-9 ‘-‘ }else if(type.equals("phone")){ s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"") .append(DaoUtil.nullToString(ht.get(name))).append("\" style=\"border:#999 1px solid;height: 22px;width: 164px;\"") .append(" onKeyPress=\"if(event.keyCode<45||event.keyCode==46||event.keyCode==47||event.keyCode>57)event.returnValue=false;\" />"); // 金额 0-9 ‘-‘ ‘.‘ }else if(type.equals("money")){ s.append("<input type=\"text\" id=\"").append(name).append("\" name=\"").append(name).append("\" value=\"") .append(DaoUtil.nullToString(ht.get(name))).append("\" style=\"border:#999 1px solid;height: 22px;width: 164px;\"") .append(" onKeyPress=\"if(event.keyCode<45||event.keyCode==47||event.keyCode>57)event.returnValue=false;\" />"); } }else { s.append(DaoUtil.nullToString(ht.get(name))); } // 文本域 }else if(type.equals("textarea")){ if(DaoUtil.nullToString(DaoUtil.HASHTAGS.get("ISNEEDTEXTAREA-"+name)).equals("no")){ s.append("<div style=\"margin-top: 5px;margin-bottom: 5px;\"><span style=\"margin-left: 20px;font-size: 14px;\">"+DaoUtil.nullToString(ht.get(name))+"</span></div>"); }else { s.append("<textarea rows=\"6\" cols=\"130\" style=\"border:#999 1px solid;\" id=\"").append(name).append("\" name=\"").append(name) .append("\" ").append(flag?"":"readonly").append(">").append(DaoUtil.nullToString(ht.get(name))).append("</textarea>"); } DaoUtil.HASHTAGS.remove("ISNEEDTEXTAREA-"+name); }else if(type.equals("textarea2")){ if(DaoUtil.nullToString(DaoUtil.HASHTAGS.get("ISNEEDTEXTAREA-"+name)).equals("no")){ s.append("<div style=\"margin-top: 5px;margin-bottom: 5px;\"><span style=\"margin-left: 20px;font-size: 14px;\">"+DaoUtil.nullToString(ht.get(name))+"</span></div>"); }else { s.append("<textarea rows=‘6‘ style=\"border:#999 1px solid; width: 90%; overflow-y: auto;\" id=\"").append(name).append("\" name=\"").append(name) .append("\" ").append(flag?"":"readonly").append(">").append(DaoUtil.nullToString(ht.get(name))).append("</textarea>"); } DaoUtil.HASHTAGS.remove("ISNEEDTEXTAREA-"+name); // 复选框1 disabled }else if(type.equals("checkbox")){ String[] arr = DaoUtil.HASHTAGS.get("checkbox-"+name).toString().split(","); for(int i=0;i<arr.length;i++){ s.append("<label style=\"margin-right: 10px;\"><input type=\"checkbox\" name=\"").append(name).append("\" value=\"") .append(arr[i]).append("\" ").append(flag?"":" disabled").append(DaoUtil.nullToString(ht.get(name)) .indexOf(arr[i])>-1?" checked":"").append(">").append(arr[i]).append("</label>"); } DaoUtil.HASHTAGS.remove("checkbox-"+name); // 复选框2 return false }else if(type.equals("checkbox2")){ String[] arr = DaoUtil.HASHTAGS.get("checkbox2-"+name).toString().split(","); for(int i=0;i<arr.length;i++){ s.append("<label style=\"margin-right: 10px;\"><input type=\"checkbox\" name=\"").append(name).append("\" value=\"") .append(arr[i]).append("\" ").append(flag?"":" onclick=\"return false;\"").append(DaoUtil.nullToString(ht.get(name)) .indexOf(arr[i])>-1?" checked":"").append(">").append(arr[i]).append("</label>"); } DaoUtil.HASHTAGS.remove("checkbox2-"+name); // 单选框 }else if(type.equals("radio")){ String[] arr = DaoUtil.HASHTAGS.get("radio-"+name).toString().split(","); for(int i=0;i<arr.length;i++){ s.append("<label style=\"margin-right: 10px;\"><input type=\"radio\" name=\"").append(name).append("\" value=\"") .append(arr[i]).append("\" ").append(flag?"":" disabled") .append(DaoUtil.nullToString(ht.get(name)).equals(arr[i])?" checked":"").append(">").append(arr[i]).append("</label>"); } DaoUtil.HASHTAGS.remove("radio-"+name); }else if(type.equals("radio2")){ if(flag){ String[] arr = DaoUtil.HASHTAGS.get("radio2-"+name).toString().split(","); for(int i=0;i<arr.length;i++){ s.append("<label style=\"margin-right: 10px;\"><input type=\"radio\" name=\"").append(name).append("\" value=\"") .append(arr[i]).append("\" ").append(flag?"":" disabled") .append(DaoUtil.nullToString(ht.get(name)).equals(arr[i])?" checked":"").append(">").append(arr[i]).append("</label>"); } }else { s.append(DaoUtil.nullToString(ht.get(name))); } DaoUtil.HASHTAGS.remove("radio2-"+name); }else if(type.equals("hidden")){ s.append("<input type=\"hidden\" name=\"").append(name).append("\" value=\"") .append(DaoUtil.nullToString(ht.get(name))).append("\" />").append(flag?DaoUtil.nullToString(ht.get(name)):""); }else if(type.equals("select-one-value")){ String[] arr = DaoUtil.HASHTAGS.get("select-value-"+name).toString().split("\\|"); String[] key = arr[0].split(","); String[] value = arr[1].split(","); if(flag){ s.append("<select id=\"").append(name).append("\" name=\"") .append(name).append("\" style=\"width:164px;border:#999 1px solid;\">").append("<option value=\"\" selected=\"selected\">请选择...</option>"); for(int i=0;i<value.length;i++){ s.append("<option value=\"").append(value[i]).append("\" ").append(DaoUtil.nullToString(ht.get(name)).equals(value[i])? "selected":"").append(">").append(key[i]).append("</option>"); } s.append("</select>"); }else { for(int i=0;i<value.length;i++){ if(DaoUtil.nullToString(ht.get(name)).equals(value[i])){ s.append(key[i]); } } } DaoUtil.HASHTAGS.remove("select-value-"+name); } return s.toString(); } /** * @param arg0 输入框类型 * @param arg1 * @param arg2 name * @param arg3 是否编辑 * @param arg4 宽 * @return */ public static String getEditInput(String arg0, Hashtable arg1, String arg2, boolean arg3, String arg4){ return getEditInput(arg0, arg1, arg2, arg3, arg4, "", ""); } /** * @param arg0 输入框类型 * @param arg1 * @param arg2 name * @param arg3 是否编辑 * @param arg4 宽 * @param arg5 是否校验 * @return */ public static String getEditInput(String arg0, Hashtable arg1, String arg2, boolean arg3, String arg4, String arg5){ return getEditInput(arg0, arg1, arg2, arg3, arg4, arg5, ""); } /** * @param arg0 输入框类型 * @param arg1 * @param arg2 name * @param arg3 是否编辑 * @param arg4 宽 * @param arg5 是否校验 * @param arg6 自定义参数 * @return */ public static String getEditInput(String arg0, Hashtable arg1, String arg2, boolean arg3, String arg4, String arg5, String arg6){ StringBuffer s = new StringBuffer(); String validator = ""; if(!DaoUtil.nullToString(arg5).isEmpty()){ validator="validator_input=‘"+arg5+"‘ "; } if(arg0.equals("text")){ if(arg3){ s.append("<input type=\"text\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" style=\"border:#999 1px solid;height:22px;width:").append(arg4) .append(";vertical-align: middle;line-height: 22px;\" ").append(validator).append(DaoUtil.nullToString(arg6)).append(" />"); }else { s.append("<input type=\"hidden\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" />").append(DaoUtil.nullToNBSP(arg1.get(arg2))); } // 数字 0-9 }else if(arg0.equals("number")){ if(arg3){ s.append("<input type=\"text\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" style=\"border:#999 1px solid;height:22px;width:").append(arg4) .append(";\"").append(" onfocus=\"this.style.imeMode=‘disabled‘\" onKeyPress=\"if(event.keyCode<48||event.keyCode>57)event.returnValue=false;\" ") .append(validator).append(DaoUtil.nullToString(arg6)).append(" />"); }else { s.append("<input type=\"hidden\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" />").append(DaoUtil.nullToNBSP(arg1.get(arg2))); } // 金额 0-9 ‘-‘ ‘.‘ }else if(arg0.equals("money")){ if(arg3){ s.append("<input type=\"text\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.getDecimalFormat("decimal", arg1.get(arg2))).append("\" style=\"border:#999 1px solid;height: 22px;width:").append(arg4).append(";\" ") .append(" onfocus=\"this.style.imeMode=‘disabled‘\" onKeyPress=\"if(event.keyCode<45||event.keyCode==47||event.keyCode>57)event.returnValue=false;\" ") .append(validator).append(DaoUtil.nullToString(arg6)).append(" />"); }else { s.append("<input type=\"hidden\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.getDecimalFormat("decimal", arg1.get(arg2))).append("\" />").append(DaoUtil.nullToNBSP(DaoUtil.getDecimalFormat("decimal", arg1.get(arg2)))); } // 下拉框 }else if(arg0.equals("select-one-value")){ String[] arr = DaoUtil.HASHTAGS.get("select-value-"+arg2).toString().split("\\|"); if(arr.length==2){ String[] key = arr[0].split(","); String[] value = arr[1].split(","); if(key.length==value.length){ if(arg3){ s.append("<select id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" style=\"width:") .append(arg4).append(";border:#999 1px solid;\" ").append(validator).append(DaoUtil.nullToString(arg6)) .append(">").append("<option value=\"\" selected=\"selected\">请选择...</option>"); for(int i=0;i<value.length;i++){ s.append("<option value=\"").append(value[i]).append("\" ").append(DaoUtil.nullToString(arg1.get(arg2)).equals(value[i])? "selected":"").append(">").append(key[i]).append("</option>"); } s.append("</select>"); }else { for(int i=0;i<value.length;i++){ if(DaoUtil.nullToString(arg1.get(arg2)).equals(value[i])){ s.append(key[i]); } } } } } DaoUtil.HASHTAGS.remove("select-value-"+arg2); }else if(arg0.equals("select-one")){ if(arg3){ String[] arr = DaoUtil.HASHTAGS.get("select-"+arg2).split(","); s.append("<select id=\"").append(arg2) .append("\" name=\"").append(arg2).append("\" style=\"width:").append(arg4).append(";border:#999 1px solid;\" ").append(validator) .append(DaoUtil.nullToString(arg6)).append(">").append("<option value=\"\" selected=\"selected\">请选择...</option>"); for(int i=0;i<arr.length;i++){ s.append("<option value=\"").append(arr[i]).append("\" ").append(DaoUtil.nullToString(arg1.get(arg2)).equals(arr[i])? "selected":"").append(">").append(arr[i]).append("</option>"); } s.append("</select>"); }else { s.append(DaoUtil.nullToNBSP(arg1.get(arg2))); } DaoUtil.HASHTAGS.remove("select-"+arg2); }else if(arg0.equals("select-custom")){ String selValue = DaoUtil.HASHTAGS.get("selcustom-"+arg2).toString(); String[] arr = selValue.split("\\|"); if(arr.length==2){ String[] key = arr[0].split(","); String[] value = arr[1].split(","); if(key.length==value.length){ if(arg3){ s.append("<input type=\"text\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" readonly=‘readonly‘ value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" style=\"border:#999 1px solid;height:22px;width:").append(arg4) .append(";vertical-align: middle;line-height: 22px;\" ").append(validator).append(DaoUtil.nullToString(arg6)) .append(" onclick=‘textclick(this);‘ />"); s.append("<div class=‘divcls‘ id=‘"+arg2+"div‘ oncontextmenu=‘javascript:event.returnValue=false;‘>"); for(int i=0;i<value.length;i++){ s.append("<div title=‘"+key[i]+"‘ onmouseover=‘mouseover(this);‘ onmouseout=‘mouseout(this);‘ onclick=‘divclick(this);‘ value=‘"+value[i]+"‘>"+key[i]+"</div>"); } s.append("</div>"); }else { for(int i=0;i<value.length;i++){ if(DaoUtil.nullToString(arg1.get(arg2)).equals(value[i])){ s.append(key[i]); } } } } }else { if(arg3){ String[] a = selValue.split(","); s.append("<input type=\"text\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" readonly=‘readonly‘ value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" style=\"border:#999 1px solid;height:22px;width:").append(arg4) .append(";vertical-align: middle;line-height: 22px;\" ").append(validator).append(DaoUtil.nullToString(arg6)) .append(" onclick=‘textclick(this);‘ />"); s.append("<div class=‘divcls‘ id=‘"+arg2+"div‘ oncontextmenu=‘javascript:event.returnValue=false;‘ onclick=\"javascript:this.style.display=‘none‘;\">"); for(int i=0;i<a.length;i++){ s.append("<div title=‘"+a[i]+"‘ onmouseover=‘mouseover(this);‘ onmouseout=‘mouseout(this);‘ onclick=‘divclick(this);‘ value=‘"+a[i]+"‘>"+a[i]+"</div>"); } s.append("</div>"); }else { s.append(DaoUtil.nullToNBSP(arg1.get(arg2))); } } DaoUtil.HASHTAGS.remove("selcustom-"+arg2); }else if(arg0.equals("textarea")){ if(arg3){ s.append("<textarea style=\"border:#999 1px solid;width:").append(arg4).append(";height:55px;overflow-y:visible;\" id=\"") .append(arg2).append("\" name=\"").append(arg2).append("\" ").append(validator).append(DaoUtil.nullToString(arg6)) .append(">").append(DaoUtil.nullToString(arg1.get(arg2))).append("</textarea>"); }else { s.append(DaoUtil.nullToNBSP(arg1.get(arg2))); } }else if(arg0.equals("date")){ if(arg3){ s.append("<input type=\"text\" id=\"").append(arg2).append("\" name=\"").append(arg2).append("\" value=\"") .append(DaoUtil.nullToString(arg1.get(arg2))).append("\" class=\"Wdate\" style=\"border:#999 1px solid;height: 22px;width: ").append(arg4) .append(";\" onClick=\"WdatePicker({readOnly:true,dateFmt:‘yyyy-MM-dd‘,isShowClear:false})\" ").append(validator) .append(DaoUtil.nullToString(arg6)).append(" />"); }else { s.append(DaoUtil.nullToNBSP(arg1.get(arg2))); } }else if("checkbox".equals(arg0)){ if(arg3){ String[] arr = DaoUtil.HASHTAGS.get("checkbox-"+arg2).toString().split(","); for(int i=0;i<arr.length;i++){ s.append("<label style=\"margin-right: 10px;\"><input type=\"checkbox\" name=\"").append(arg2).append("\" value=\"") .append(arr[i]).append("\" ").append(DaoUtil.nullToString(arg1.get(arg2)) .indexOf(arr[i])>-1?" checked=‘checked‘":"").append("/>").append(arr[i]).append("</label>"); } } DaoUtil.HASHTAGS.remove("checkbox-"+arg2); }else if("hidden".equals(arg0)){ if(arg3){ s.append("<input type=‘hidden‘ name=‘"+arg2+"‘ id=‘"+arg2+"‘ value=‘"+DaoUtil.nullToString(arg1.get(arg2))+"‘ />"+DaoUtil.nullToNBSP(arg1.get(arg2))); }else { s.append("<input type=‘hidden‘ name=‘"+arg2+"‘ id=‘"+arg2+"‘ value=‘"+DaoUtil.nullToString(arg1.get(arg2))+"‘ />"); } } return s.toString(); } /** * 自定义下拉框 * @param name * @param value * @param size * @return */ public static String getCustomSelect(String name, String value, int size){ StringBuffer s = new StringBuffer(); String[] a = value.split(","); s.append("<div class=‘divcls‘ id=‘" + name + "div‘ style=‘height:" + (20 * size + 3) + "px;‘ oncontextmenu=‘return false;‘ onclick=‘$(this).hide();‘>\n"); for (int i = 0; i < a.length; i++) { s.append("<div title=‘" + a[i] + "‘ onclick=‘divclick(this);‘ value=‘" + a[i] + "‘ onmouseover=‘mouseover(this);‘ onmouseout=‘mouseout(this);‘>" + a[i] + "</div>\n"); } s.append("</div>\n"); return s.toString(); } /** * 自定义下拉框 * 引用jquery.select.js * @param list List《Hashtable《String,Object》》 list * @param k * @param vs * @param join 多个字符串采用的连接符,默认为‘:’ * @return */ /** * 自定义下拉框 * 引用jquery.select.js * @param list List《Hashtable《String,Object》》 list * @param id div选项的id * @param valueK 点击选项后,填充到输入框中的值 * @param showKs 通过此数组给定要在选项上展示的值,在hashtable中所对应的k * @param callback 点击选项后执行的回调 * @param style 样式 * @param join 多个字符串采用的连接符,不填默认为‘:’ * @return */ public static String getCustomSelect(List<Hashtable<String,Object>> list,String id,String valueK,String[] showks,String callback,String style,String... join){ StringBuffer s=new StringBuffer(); if(list==null||list.isEmpty()||StringUtil.isEmpty(id)||StringUtil.isEmpty(valueK)){ return ""; } String joinstr=(join.length<1)||StringUtil.isEmpty(join[0])?":":join[0]; Hashtable<String,Object> h=null; s.append("<div class=‘divcls‘ id="+id+" style=‘"+style+"‘ " + "oncontextmenu=‘return false;‘ onclick=‘$(this).hide();‘> "); for(int i=0,len=list.size();i<len;i++){ h=list.get(i); String showVal=""; for (int j = 0; j < showks.length; j++) { if(j==0){ showVal+=h.get(showks[j]).toString(); continue; } showVal+=joinstr+h.get(showks[j]).toString(); } s.append("<div title=‘" + h.get(valueK).toString() + "‘ onclick=‘$.fn.divclick(this,"+callback+");‘ value=‘"+h.get(valueK).toString()+"‘" +" onmouseover=‘$.fn.mouseover(this);‘ onmouseout=‘$.fn.mouseout(this);‘ >"+showVal+"</div>"); } s.append("</div>\n"); return s.toString(); } /** * button * @param name * @param value * @param params * @param flag * @return */ public static String getButton(String name, String value, String params, boolean flag) { StringBuffer s = new StringBuffer(); if (flag) { s.append("<input type=‘button‘ id=‘"+name+"‘ name=‘"+name+"‘ value=‘"+value+"‘ "+params+" />"); } return s.toString(); } /** * date * @param name * @param value * @param flag * @param style * @param picker dateFmt:‘yyyy-MM-dd‘,qsEnabled:true,isShowClear:true,isShowToday:true,isShowOthers:true,readOnly:false * @param params * @return */ public static String getDate(String name, Object value, boolean flag, String style, String picker, String params){ StringBuffer s = new StringBuffer(); if(flag){ String df = ""; if (params != null && !"".equals(params)) { if(params.indexOf("<DF>")>-1&¶ms.indexOf("</DF>")>params.indexOf("<DF>")){ df = params.substring(params.indexOf("<DF>")+4, params.indexOf("</DF>")); params = params.replace("<DF>"+df+"</DF>", ""); } } String val = DaoUtil.nullToString(value); if("".equals(val)){ val = df; } s.append("<input type=‘text‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + val + "\" class=‘Wdate‘ style=\"border:#999 1px solid;" + DaoUtil.nullToString(style) + "\" onClick=\"WdatePicker({" + DaoUtil.nullToString(picker) + "})\" " + DaoUtil.nullToString(params) + " />"); }else { s.append(getHidden(name, value, false)); s.append(DaoUtil.nullToNBSP(value)); } return s.toString(); } /** * text * @param name * @param value * @param flag * @param style height: 22px;vertical-align: middle;line-height: 22px; * @param params * @return */ public static String getInput(String name, Object value, boolean flag, String style, String params){ StringBuffer s = new StringBuffer(); if(flag){ s.append("<input type=‘text‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" style=\"border:#999 1px solid;" + DaoUtil.nullToString(style) + "\" " + DaoUtil.nullToString(params) + " />"); }else { s.append("<input type=‘hidden‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value)+ "\" />"); s.append(DaoUtil.nullToNBSP(value)); } return s.toString(); } /** * number * @param name * @param value * @param flag * @param style * @param params * @return */ public static String getNumber(String name, Object value, boolean flag, String style, String params){ StringBuffer s = new StringBuffer(); if(flag){ s.append("<input type=‘text‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" style=\"border:#999 1px solid;" + DaoUtil.nullToString(style) + "\" onfocus=\"this.style.imeMode=‘disabled‘\"" + "onKeyPress=‘if(event.keyCode<48||event.keyCode>57)event.returnValue=false;‘ " + DaoUtil.nullToString(params) + " />"); }else { s.append(DaoUtil.nullToNBSP(value)); } return s.toString(); } /** * phone * @param name * @param value * @param flag * @param style * @param params * @return */ public static String getPhone(String name, Object value, boolean flag, String style, String params){ StringBuffer s = new StringBuffer(); if(flag){ s.append("<input type=‘text‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" style=\"border:#999 1px solid;" + DaoUtil.nullToString(style) + "\" onfocus=\"this.style.imeMode=‘disabled‘\"" + "onKeyPress=\"if(event.keyCode!=45&&(event.keyCode<48||event.keyCode>57)){event.returnValue=false;}else{if(event.keyCode==45&&(this.value==‘‘||this.value.indexOf(‘-‘)>-1)){event.returnValue=false;}}\" " + DaoUtil.nullToString(params) + " />"); }else { s.append(DaoUtil.nullToNBSP(value)); } return s.toString(); } /** * money * @param name * @param value * @param flag * @param style * @param params * @return */ public static String getMoney(String name, Object value, boolean flag, String style, String params){ StringBuffer s = new StringBuffer(); if(flag){ s.append("<input type=‘text‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" style=\"border:#999 1px solid;" + DaoUtil.nullToString(style) + "\" onfocus=\"this.style.imeMode=‘disabled‘\"" + " onKeyPress=\"if(event.keyCode<46||event.keyCode==47||event.keyCode>57){event.returnValue=false;}else{if(" +"event.keyCode==46&&(this.value==‘‘||this.value.indexOf(‘.‘)>-1)){event.returnValue=false;}}\" " + DaoUtil.nullToString(params) + " />"); }else { s.append(DaoUtil.nullToNBSP(DaoUtil.getDecimalFormat("decimal", value))); } return s.toString(); } /** * money * @param name * @param value * @param flag * @param style * @param params * @return */ public static String getMoney2(String name, Object value, boolean flag, String style, String params){ StringBuffer s = new StringBuffer(); if(flag){ s.append("<input type=‘text‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" style=\"border:#999 1px solid;" + DaoUtil.nullToString(style) + "\" onfocus=\"this.style.imeMode=‘disabled‘\"" + " onKeyPress=\"if(event.keyCode<45||event.keyCode==47||event.keyCode>57){event.returnValue=false;}else if" + "(event.keyCode==45&&this.value!=‘‘){event.returnValue=false;} " + "else{if(event.keyCode==46&&(this.value==‘‘||this.value.indexOf(‘.‘)>-1)){event.returnValue=false;}}\" " + DaoUtil.nullToString(params) + " />"); }else { s.append("<input type=‘hidden‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value)+ "\" />"); s.append(DaoUtil.nullToNBSP(DaoUtil.getDecimalFormat("decimal", value))); } return s.toString(); } /** * hidden * @param name * @param value * @param flag * @return */ public static String getHidden(String name, Object value, boolean flag){ StringBuffer s = new StringBuffer(); s.append("<input type=‘hidden‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" />"); if(flag){ s.append(DaoUtil.nullToNBSP(value)); } return s.toString(); } public static String getHidden(String name, Object value, boolean flag,String spanName){ StringBuffer s = new StringBuffer(); s.append("<input type=‘hidden‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" + DaoUtil.nullToString(value) + "\" />"); if(flag){ s.append("<span id=‘"+spanName+"‘ name=‘"+spanName+"‘ >").append(DaoUtil.nullToNBSP(value)).append("</span>"); } return s.toString(); } /** * select * @param name * @param value * @param option * @param flag * @param style * @param params * @return */ public static String getSelect(String name, Object value, String option, boolean flag, String style, String params){ if(value == null){ value = ""; } StringBuffer s = new StringBuffer(); if(option!=null && !"".equals(option)){ String df = ""; if (params != null && !"".equals(params)) { if(params.indexOf("<DF>")>-1&¶ms.indexOf("</DF>")>-1){ df = params.substring(params.indexOf("<DF>")+4, params.indexOf("</DF>")); params = params.replace("<DF>"+df+"</DF>", ""); } } String[] a = option.split("\\|"); if(a.length==2){ String[] k = a[0].split(","); String[] v = a[1].split(","); if(k.length==v.length){ if(flag){ s.append("<select id=‘"+name+"‘ name=‘"+name+"‘ style=\"border:#999 1px solid;" +DaoUtil.nullToString(style)+"\" "+DaoUtil.nullToString(params)+">"); s.append("<option value=‘‘ selected>请选择...</option>"); if("".equals(value.toString())){ value = df; } for(int i=0;i<v.length;i++){ s.append("<option value=\""+v[i]+"\" "+(v[i].equals(value.toString())?"selected":"")+">"+k[i]+"</option>"); } s.append("</select>"); }else { for(int i=0;i<v.length;i++){ if(v[i].equals(value.toString())){ s.append("<input type=‘hidden‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" +v[i]+ "\" />"); s.append(k[i]); break; } } } } }else { String[] k = option.split(","); if(flag){ s.append("<select id=‘"+name+"‘ name=‘"+name+"‘ style=\"border:#999 1px solid;" +DaoUtil.nullToString(style)+"\" "+DaoUtil.nullToString(params)+">"); s.append("<option value=‘‘ selected>请选择...</option>"); for(int i=0;i<k.length;i++){ if("".equals(value.toString())){ value = df; } s.append("<option value=\""+k[i]+"\" "+(k[i].equals(value.toString())?"selected":"")+">"+k[i]+"</option>"); } s.append("</select>"); }else { s.append(value.toString()); } } } else { s.append("<select id=‘"+name+"‘ name=‘"+name+"‘ style=\"border:#999 1px solid;" +DaoUtil.nullToString(style)+"\" "+DaoUtil.nullToString(params)+">"); s.append("<option value=‘‘ selected>请选择...</option>"); s.append("</select>"); } return s.toString(); } /** * radio * @param name * @param value * @param option * @param flag * @param style * @param params * @return */ public static String getRadio(String name, Object value, String option, boolean flag, String style, String params){ if(value == null){ value = ""; } StringBuffer s = new StringBuffer(); if(option!=null && !"".equals(option)){ String df = ""; if (params != null && !"".equals(params)) { if(params.indexOf("<DF>")>-1&¶ms.indexOf("</DF>")>-1){ df = params.substring(params.indexOf("<DF>")+4, params.indexOf("</DF>")); params = params.replace("<DF>"+df+"</DF>", ""); } } String[] a = option.split("\\|"); if(a.length==2){ String[] k = a[0].split(","); String[] v = a[1].split(","); if(k.length==v.length){ if(flag){ if("".equals(value)){ value = df; } for(int i=0;i<v.length;i++){ s.append("<label style=‘" + DaoUtil.nullToString(style) + "‘><input type=‘radio‘ name=‘" + name + "‘ value=\"" + v[i] + "\" " + (v[i].equals(value.toString()) ? " checked" : "") + " style=‘margin-right:2px;‘ " + DaoUtil.nullToString(params) + " />" + k[i] + "</label>"); } }else { for(int i=0;i<v.length;i++){ if(v[i].equals(value.toString())){ s.append(k[i]); break; } } } } }else { String[] k = option.split(","); if(flag){ if("".equals(value)){ value = df; } for(int i=0;i<k.length;i++){ s.append("<label style=‘" + DaoUtil.nullToString(style) + "‘><input type=‘radio‘ name=‘" + name + "‘ value=\"" + k[i] + "\" " + (k[i].equals(value.toString()) ? " checked" : "") + " style=‘margin-right:2px;‘ " + DaoUtil.nullToString(params) + " />" + k[i] + "</label>"); } }else { s.append(DaoUtil.nullToString(value)); } } } return s.toString(); } /** * 多选框checkbox * @param name * @param value * @param option * @param flag * @param style * @param params * @return */ public static String getCheckbox(String name, Object value, String option, boolean flag, String style, String params){ if(value == null){ value = ""; } StringBuffer s = new StringBuffer(); if(option!=null && !"".equals(option)){ String[] a = option.split("\\|"); if(a.length==2){ String[] k = a[0].split(","); String[] v = a[1].split(","); if(k.length==v.length){ if(flag){ for(int i=0;i<v.length;i++){ s.append("<label style=‘" + DaoUtil.nullToString(style) + "‘><input type=‘checkbox‘ name=‘" + name + "‘ value=\"" + v[i] + "\" " + (v[i].equals(value.toString()) ? " checked" : "") + " style=‘margin-right:2px;‘ " + DaoUtil.nullToString(params) + " />" + k[i] + "</label>"); } }else { for(int i=0;i<v.length;i++){ if(v[i].equals(value.toString())){ s.append(k[i]); break; } } } } }else { String[] k = option.split(","); if(flag){ for(int i=0;i<k.length;i++){ s.append("<label style=‘" + DaoUtil.nullToString(style) + "‘><input type=‘checkbox‘ name=‘" + name + "‘ value=\"" + k[i] + "\" " + (k[i].equals(value.toString()) ? " checked" : "") + " style=‘margin-right:2px;‘ " + DaoUtil.nullToString(params) + " />" + k[i] + "</label>"); } }else { s.append(value.toString()); } } } return s.toString(); } /** * 列表checkBox * @param id * @param name * @param value * @param flag * @param params * @return */ public static String getListBox(String id, String name, Object value, boolean flag, String params){ StringBuffer s = new StringBuffer(); if(flag) { s.append("<input type=‘checkbox‘ id=‘" + DaoUtil.nullToString(id) + "‘ name=‘" + DaoUtil.nullToString(name) + "‘ value=\"" + DaoUtil.nullToString(value) + "\" " + DaoUtil.nullToString(params) + " />"); } else { s.append(" "); } return s.toString(); } /** * textArea * @param name * @param value * @param flag * @param style * @param params * @return */ public static String getTextArea(String name, Object value, boolean flag, String style, String params){ StringBuffer s = new StringBuffer(); if(flag){ s.append("<textarea style=\"border:#999 1px solid; " + DaoUtil.nullToString(style) + "\" id=‘" + name + "‘ name=‘" + name + "‘ " + DaoUtil.nullToString(params) + ">" + DaoUtil.nullToString(value) + "</textarea>"); }else { s.append("<div style=\"margin-top: 5px;margin-bottom: 5px;\"><span style=\"font-size: 14px;\">" + DaoUtil.nullToNBSP(value) + "</span></div>"); s.append("<input type=‘hidden‘ id=‘" + name + "‘ name=‘" + name + "‘ value=\"" +value+ "\" />"); } return s.toString(); } /** * 表单input * @param name * @param ht * @param type input类型 * @param flag 能否编辑 * @return */ public static String getEditInput2(String name, Hashtable ht, String type, boolean flag){ StringBuffer s = new StringBuffer(); if(type.equals("select-one-value")){ String[] arr = DaoUtil.nullToString(DaoUtil.HASHTAGS.get("select-value-"+name)).split("\\|"); if(arr.length==2){ String[] key = arr[0].split(","); String[] value = arr[1].split(","); if(flag){ s.append("<select id=\"").append(name).append("\" name=\"") .append(name).append("\" style=\"width:164px;border:#999 1px solid;\">").append("<option value=\" \" selected=\"selected\">请选择...</option>"); for(int i=0;i<value.length;i++){ s.append("<option value=\"").append(value[i]).append("\" ").append(DaoUtil.nullToString(ht.get(name)).equals(value[i])? "selected":"").append(">").append(key[i]).append("</option>"); } s.append("</select>"); }else { for(int i=0;i<value.length;i++){ if(DaoUtil.nullToString(ht.get(name)).equals(value[i])){ s.append(key[i]); } } } DaoUtil.HASHTAGS.remove("select-value-"+name); } } return s.toString(); } /** * * @param id id * @param value <sapn>value</span> * @param style style属性值 * @return */ public static String getSpan(String id,String bindData,String value,String style){ StringBuffer buf=new StringBuffer(); buf.append("<span ") .append("id=‘") .append(id) .append("‘ value=‘") .append(bindData) .append("‘ style=‘") .append(StringUtil.isEmpty(style)?"":style.trim()) .append("‘>") .append(value) .append("</span>"); return buf.toString(); } /** * 使用此方法需要引入 util.js 或者重写 Util.pageJump 方法 * 获得一个分页条 * @param page { * pageCount:"总页数", * currPage:"当前页", * rowCount:"总记录数" * } * @param callback 点击分页条之后执行的回调函数名 */ public static String getPaingPilot(Page page, String callback) { StringBuffer html=new StringBuffer(); html.append("<table width=‘99%‘>") .append("<tr style=‘height:25px;‘>") .append("<td class=‘riskPage hsebg_td02‘ id=‘page‘ pageCount=‘") .append(page.getPageCount()) .append("‘ currPage=‘") .append(page.getCurrPage()) .append("‘>") .append("<span style=‘MARGIN-RIGHT: 20px‘ hasbox=‘2‘>") .append("<span id=‘rowCount‘>共") .append(page.getRowCount()) .append("条记录</span>") .append("<a id=‘firstPage‘ onclick=‘Util.pageJump(this,") .append(callback) .append(")‘ href=‘javascript:;‘>首页</a> |") .append("<a id=‘prePage‘ onclick=‘Util.pageJump(this,") .append(callback) .append(")‘ href=‘javascript:;‘>上一页</a> |") .append("<a id=‘nextPage‘ onclick=‘Util.pageJump(this,") .append(callback) .append(")‘ href=‘javascript:;‘>下一页</a> |") .append("<a id=‘lastPage‘ onclick=‘Util.pageJump(this,") .append(callback) .append(")‘ href=‘javascript:;‘>末页</a> 第 ") .append(page.getCurrPage()) .append("页 / 共") .append(page.getPageCount()) .append(" 页</span></td>") .append("</tr>") .append("</table>"); return html.toString(); } /** * 使用此方法需要引入 util.js 或者重写 Util.pageJump 方法 * @param hashtable{ * pageCount:"总页数", * currPage:"当前页", * rowCount:"总记录数", * pageSize:"每页记录数" * } * @param callback 点击分页条选项之后执行的回调函数名 * @return */ public static String getPaingPilot(Hashtable data, String callback) { String pageSize=StringUtil.isEmpty(data.get("pageSize"))?"10":data.get("pageSize").toString(); String rowCount=StringUtil.isEmpty(data.get("rowCount"))?"0":data.get("rowCount").toString(); String currPage=StringUtil.isEmpty(data.get("currPage"))?"0":data.get("currPage").toString(); return getPaingPilot(new Page(Integer.valueOf(pageSize),Integer.valueOf(rowCount),Integer.valueOf(currPage)),callback); } /** * 获得一个固定选中的下拉选 * @param selectId * @param optionId * @param optionVal * @return */ public static String getFixedSelectOption(String selectId,Object optionId,String optionVal){ StringBuffer option=new StringBuffer(); option.append("<select id=‘") .append(selectId) .append("‘ name=‘") .append(selectId) .append("‘ >") .append("<option value=‘") .append(optionId) .append("‘ selected >") .append(optionVal) .append("</option>") .append("</select>"); return option.toString(); } }
原文地址:https://www.cnblogs.com/demon09/p/9083177.html
时间: 2024-10-17 04:55:28