版本3.0构造两个字典并解决查询字典条目时只能查本页的问题

 DictionaryModel:

package cn.hnisi.gdrk.models.sys.dictionary; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import org.apache.commons.lang.StringUtils; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import cn.hnisi.architecture.AbstractModel; import cn.hnisi.architecture.common.util.CommonUtil; import cn.hnisi.dict.dictionary.Dictionary; import cn.hnisi.dict.dictionary.DictionaryDAOEx; import cn.hnisi.dict.dictionarykind.DictionaryKind; import cn.hnisi.gdrk.utils.BizGlobalConstants; import cn.hnisi.gdrk.utils.CommonFunction; import cn.hnisi.gdrk.utils.GenarateConnection; import cn.hnisi.gdrk.utils.GlobalConstants; import cn.hnisi.gdrk.workflow.jbpmengine.util.QueryConVo; /** * * @author:denghuimin ,yanghanming * @createTime:Jul 7, 2009 9:41:56 AM * @function:字典条目类 */ @SuppressWarnings("unchecked") public class DictionaryModel extends AbstractModel { private Dictionary dictionary; private Dictionary cloneDic; private DictionaryKind dictionaryKind; private DictionaryDAOEx dictionaryDAOEx; private String kindTemp; private String detailTemp; // 控件可操作标志 private boolean bolSave = true; private boolean bolInput = true; private boolean bolModify = false; private boolean bolCancel = true; // 是否可保存标志 private boolean bolCanSave = true; private boolean bolUpdate = true; // 分页控制标志 private boolean bolByQuery = true; private List<Dictionary> diclist; // 查询条件变量 private String codeCondition; // 区分更新还是保存变量 private String save = null; // 字典条目变量 private String dictionaryKinds; private String dictionaryCode; private String dictionaryDetail; private String dictionarySpell; private String dictionaryWb; private String dictionaryHomophony; private String dictionarySource; private String dictionaryNote; private String dictionaryAimKind; private String dictionaryAimCode; private String dictionaryAimDetail; // 目标字典动态过滤使用的sql private String aimSql = null; // 常量 private static final String SCBZ0 = "0"; private static final String SCBZ1 = "1"; private static final String ModifyDictionaryPane = "ModifyDictionaryPane"; private static final String DictionaryListPane = "DictionaryListPane"; private static final String AddDictionaryPane = "AddDictionaryPane"; // 分页变量 protected int rowCount = 0; // 记录数 protected int pageCount = 0; // 总页数 protected int pageSize = GlobalConstants.DEFAULT_PAGE_SIZE;// 每页显示的条数 protected int currentPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER;// 当前页码 protected int gotoPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER; /** * * @author:denghuimin,yanghanming * @createTime:Jul 9, 2009 12:18:01 AM * @function:重写父类方法doSaveToDB */ public String doSaveToDB() { Map requestParams = FacesContext.getCurrentInstance() .getExternalContext().getRequestParameterMap(); save = (String) requestParams.get("saveFlag"); if (this.getSave().equals("save")) { this.save(); this.fromOutcome = "AddDictionaryPane"; } else { this.update(); this.fromOutcome = "ModifyDictionaryPane"; } return null; } /** * * @author:denghuimin ,yanghanming * @createTime:Jul 7, 2009 9:48:45 AM * @function:保存字典条目:先校验拼音头和字典代码,如果字典条目代码存在 (分删除标志为1和为0两种情况,删除为1,默认为0)则不保存,如果是删除了的则恢复。 * @param: * @return: */ public String save() { // 可保存标志 bolCanSave = true; // 判断是否存在相同的代码 bolCanSave = isExist(); // 不存在相同的字典条目代码则保存 if (bolCanSave) { // 因hibernate原因,数据库默认不起作用,显式设置删除标志为0 dictionary.setScbz(SCBZ0); dictionary.setDetail(this.getDictionaryDetail()); dictionary.setCode(this.getDictionaryCode()); dictionary.setSpell(this.getDictionarySpell()); dictionary.setHomophony(this.getDictionaryHomophony()); dictionary.setWb(this.getDictionaryWb()); dictionary.setSource(this.getDictionarySource()); dictionary.setNote(this.getDictionaryNote()); dictionary.setAimkind(this.getDictionaryAimKind()); dictionary.setAimdetail(this.getDictionaryAimDetail()); dictionary.setAimcode(this.getDictionaryAimCode()); dictionaryDAOEx.save(dictionary); } return null; } public boolean isExist() { // 根据字典条目类型查出所有字典条目 List<Dictionary> listTemp = dictionaryDAOEx.findByKind(dictionary .getKind()); // 存在,设置返回标志 boolean bolResult = true; // 遍历数据库中的相应的dictionary,查看代码是否存在,存在则不保存,已删除的则恢复 for (int i = 0; listTemp != null && i < listTemp.size(); i++) { // 根据字典代码比较 if (StringUtils.equals(this.getDictionaryCode(), listTemp.get(i) .getCode())) { // 存在且删除标志为0 if (StringUtils.equals(listTemp.get(i).getScbz(), SCBZ0)) { addMessage(FacesMessage.SEVERITY_WARN, null, "该字典代码已存在,请使用其他代码!"); bolResult = false; break; } else { // 存在且删除标志为1 // 恢复已删除字典条目,设置删除标志为0,并更新字典条目 listTemp.get(i).setScbz(SCBZ0); dictionary = listTemp.get(i); dictionaryDAOEx.attachDirty(dictionary); addMessage(FacesMessage.SEVERITY_INFO, null, "该字典代码已删除,现在恢复!"); bolResult = false; break; } } } return bolResult; } /** * * @author:denghuimin, yanghanming * @createTime:Jul 7, 2009 10:12:25 AM * @function:更新函数 * @return: */ public String update() { // 从原始的克隆对象再次克隆,用于比较字典代码是否发生修改,若没发生修改则可更新 Dictionary dic = (Dictionary) CommonUtil.cloneObject(cloneDic); // 若字典代码没发生变化则可更新,否则进一步判断代码是否存在 if (StringUtils.equals(dic.getCode(), dictionary.getCode())) { dictionaryDAOEx.attachDirty(dictionary); } else { bolSave = true; bolModify = false; bolCancel = true; bolInput = true; bolUpdate = isExist(); if (bolUpdate) { dictionaryDAOEx.merge(dictionary); } } return null; } /** * * @author:denghuimin, yanghanming * @createTime:Jul 7, 2009 10:09:36 AM * @function:逻辑删除字典条目 * @return: */ public String remove() { transactionTemplate.execute(new TransactionCallbackWithoutResult() { public void doInTransactionWithoutResult( TransactionStatus transactionStatus) { // 获取页面传来的字典的id,遍历diclist表,如果diclist存在相同的字典条目,则从diclist中删除 Map requestParams = FacesContext.getCurrentInstance() .getExternalContext().getRequestParameterMap(); String id = (String) requestParams.get("id"); for (int i = 0; diclist != null && i < diclist.size(); i++) { dictionary = diclist.get(i); if (dictionary.getId().equals(id)) { diclist.remove(i); break; } } // 逻辑删除字典条目,设置删除标志,1代表删除,0代表不删除 dictionary.setScbz(SCBZ1); dictionaryDAOEx.attachDirty(dictionary); } }); return null; } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:27:03 AM * @function: * @return: */ public String addDicLink() { this.dictionary.setKind(kindTemp); return AddDictionaryPane; } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:28:47 AM * @function:点击修改时候,改变控件的可用性 * @return: */ public String changeFlag() { bolSave = false; bolModify = true; bolCancel = false; bolInput = false; return null; } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:30:02 AM * @function:取消修改操作 * @return: */ public String recover() { Dictionary dic = (Dictionary) CommonUtil.cloneObject(cloneDic); this.setDictionary(dic); return null; } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:31:07 AM * @function:跳转到修改页面 * @return: */ public String to() { bolSave = true; bolModify = false; bolCancel = true; bolInput = true; // 获取页面传来的字典条目id Map requestParams = FacesContext.getCurrentInstance() .getExternalContext().getRequestParameterMap(); String id = (String) requestParams.get("id"); // 遍历diclist表,在diclist表中找到相应的字典条目 for (int i = 0; diclist != null && i < diclist.size(); i++) { Dictionary dictTemp = (Dictionary) diclist.get(i); if (dictTemp.getId().equals(id)) { this.setDictionary(dictTemp); // 克隆相应的副本作为取消修改操作时恢复字典條目 cloneDic = new Dictionary(); cloneDic = (Dictionary) CommonUtil.cloneObject(dictTemp); break; } } return ModifyDictionaryPane; } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:36:26 AM * @function: * @param otherCondition * @return: */ public String findByQueryCondition(String otherCondition) { String errMessage = ""; List list = new ArrayList<QueryConVo>(); // 点击“字典维护”链接时候,执行此函数,判断bolByQuery标志,第一次获取页面传来的字典类型kind if (bolByQuery) { bolByQuery = false; Map requestParams = FacesContext.getCurrentInstance() .getExternalContext().getRequestParameterMap(); // kindTemp,获取页面传来的字典类型的kind,并以此为条件查找对应的字典条目 kindTemp = (String) requestParams.get("kind"); // detailTemp,获取页面传来的字典类型的中文含义,用来设置字典条目列表的标题 // 页面传过来时出现非中文字符,需要转换为中文字符 detailTemp = CommonFunction .escapeSequenceToString((String) requestParams .get("detail")); this.getDictionaryKind().setDetail(detailTemp); this.getDictionaryKind().setKind(kindTemp); if (StringUtils.isNotBlank(kindTemp)) { QueryConVo conVo = new QueryConVo(dictionaryDAOEx.KIND, kindTemp); list.add(conVo); } } // 点击字典条目列表页面“查询”按钮时候,根据条件查询相应的字典条目 else { if (StringUtils.isNotBlank(kindTemp)) { QueryConVo conVo = new QueryConVo(dictionaryDAOEx.KIND, kindTemp); list.add(conVo); } } diclist = new ArrayList<Dictionary>(); GenarateConnection gc = (GenarateConnection) getCtx().getBean( BizGlobalConstants.X_GCONNECTION); String hql = "from Dictionary as ti where 1=1 and ti.scbz ='0'"; try { this.diclist = gc.findListForPage(hql, list, this .getCurrentPageNumber(), this.getPageSize()); this.rowCount = gc.findCountForPage(hql, list, this .getCurrentPageNumber(), this.getPageSize()); this.setRowCount(rowCount); } catch (Exception e) { e.printStackTrace(); } return errMessage.trim(); } /** * * @author:denghuimin , yanghanming * @createTime:Jul 7, 2009 10:46:56 AM * @function:查询时在diclist表里面查,不用再次查找数据库 * @return: */ public String findInDiclist() { String code = this.getCodeCondition(); boolean bolfind=false; List tempList = new ArrayList(); this.first(); for (int j = 0; j < this.getPageCount(); j++) { for (int i = 0; StringUtils.isNotBlank(code) && diclist != null && i < diclist.size(); i++) { dictionary = (Dictionary) diclist.get(i); if (dictionary.getCode().equals(code)) { tempList.add(dictionary); bolfind=true; break; } } if(!bolfind)this.next(); else break; } diclist = tempList; this.setRowCount(diclist.size()); return null; } public String doBriefQuery() { String errMessage = ""; errMessage = findByQueryCondition(dictionary.getKind()); this.fromOutcome = DictionaryListPane; return errMessage; } /** * 获取记录总数 * * @return */ public int getRowCount() { return rowCount; } /** * 设置记录总数 * * @param recordCount */ public void setRowCount(int recordCount) { this.rowCount = recordCount; } /** * 获取页数 */ public int getPageCount() { if ((rowCount % pageSize) == 0) { pageCount = this.rowCount / this.pageSize; } else { pageCount = this.rowCount / this.pageSize + 1; } return pageCount; } /** * 设置页数 */ public void setPageCount(int pageCount) { this.pageCount = pageCount; } /** * 获取每页记录数 */ public int getPageSize() { return pageSize; } /** * 设置每页记录数 * * @param pageSize */ public void setPageSize(int pageSize) { if (pageSize < 1) { this.pageSize = GlobalConstants.DEFAULT_PAGE_SIZE; } else { this.pageSize = pageSize; } } /** * 获取指定页 * * @return */ public int getCurrentPageNumber() { return currentPageNumber; } /** * 设置指定页 * * @param arg */ public void setCurrentPageNumber(int arg) { if (arg < 1) { this.currentPageNumber = GlobalConstants.DEFAULT_PAGE_NUMBER; } else { this.currentPageNumber = arg; } } /** * 第一页 */ public String first() { this.currentPageNumber = 1; doBriefQuery(); toMerge(); return null; } /** * 最后一页 * * @return */ public String last() { this.currentPageNumber = this.pageCount; doBriefQuery(); toMerge(); return null; } /** * 上页 */ public String previous() { this.currentPageNumber--; if (this.currentPageNumber < 1) this.currentPageNumber = 1; if (this.currentPageNumber > this.pageCount) this.currentPageNumber = this.pageCount; doBriefQuery(); toMerge(); return null; } /** * 下页 * * @return */ public String next() { this.currentPageNumber++; if (this.currentPageNumber < 1) this.currentPageNumber = 1; if (this.currentPageNumber > this.pageCount) this.currentPageNumber = this.pageCount; doBriefQuery(); toMerge(); return null; } /** * 去到指定页 * * @return */ public String go() { if (this.gotoPageNumber < 1) { this.currentPageNumber = 1; gotoPageNumber = 1; } else if (this.gotoPageNumber > this.pageCount) { this.currentPageNumber = this.pageCount; this.gotoPageNumber = this.pageCount; } else { this.currentPageNumber = this.gotoPageNumber; } doBriefQuery(); toMerge(); return null; } /* * 获取指定页 */ public int getGotoPageNumber() { return gotoPageNumber; } public void setGotoPageNumber(int gotoPageNumber) { this.gotoPageNumber = gotoPageNumber; } public Dictionary getDictionary() { return dictionary; } public void setDictionary(Dictionary dictionary) { this.dictionary = dictionary; } public Dictionary getCloneDic() { return cloneDic; } public void setCloneDic(Dictionary cloneDic) { this.cloneDic = cloneDic; } public DictionaryKind getDictionaryKind() { return dictionaryKind; } public void setDictionaryKind(DictionaryKind dictionaryKind) { this.dictionaryKind = dictionaryKind; } public DictionaryDAOEx getDictionaryDAOEx() { return dictionaryDAOEx; } public void setDictionaryDAOEx(DictionaryDAOEx dictionaryDAOEx) { this.dictionaryDAOEx = dictionaryDAOEx; } public String getKindTemp() { return kindTemp; } public void setKindTemp(String kindTemp) { this.kindTemp = kindTemp; } public String getDetailTemp() { return detailTemp; } public void setDetailTemp(String detailTemp) { this.detailTemp = detailTemp; } public boolean isBolSave() { return bolSave; } public void setBolSave(boolean bolSave) { this.bolSave = bolSave; } public boolean isBolInput() { return bolInput; } public void setBolInput(boolean bolInput) { this.bolInput = bolInput; } public boolean isBolModify() { return bolModify; } public void setBolModify(boolean bolModify) { this.bolModify = bolModify; } public boolean isBolCanSave() { return bolCanSave; } public void setBolCanSave(boolean bolCanSave) { this.bolCanSave = bolCanSave; } public boolean isBolByQuery() { return bolByQuery; } public void setBolByQuery(boolean bolByQuery) { this.bolByQuery = bolByQuery; } public List<Dictionary> getDiclist() { return diclist; } public void setDiclist(List<Dictionary> diclist) { this.diclist = diclist; } public boolean isBolCancel() { return bolCancel; } public void setBolCancel(boolean bolCancel) { this.bolCancel = bolCancel; } public static String getSCBZ0() { return SCBZ0; } public static String getSCBZ1() { return SCBZ1; } public String getCodeCondition() { return codeCondition; } public void setCodeCondition(String codeCondition) { this.codeCondition = codeCondition; } public static String getModifyDictionaryPane() { return ModifyDictionaryPane; } public static String getDictionaryListPane() { return DictionaryListPane; } public static String getAddDictionaryPane() { return AddDictionaryPane; } public String getSave() { return save; } public void setSave(String save) { this.save = save; } public String getDictionaryKinds() { return dictionaryKinds; } public void setDictionaryKinds(String dictionaryKinds) { this.dictionaryKinds = dictionaryKinds; } public String getDictionaryCode() { return dictionaryCode; } public void setDictionaryCode(String dictionaryCode) { this.dictionaryCode = dictionaryCode; } public String getDictionaryDetail() { return dictionaryDetail; } public void setDictionaryDetail(String dictionaryDetail) { this.dictionaryDetail = dictionaryDetail; } public String getDictionarySpell() { return dictionarySpell; } public void setDictionarySpell(String dictionarySpell) { this.dictionarySpell = dictionarySpell; } public String getDictionaryHomophony() { return dictionaryHomophony; } public void setDictionaryHomophony(String dictionaryHomophony) { this.dictionaryHomophony = dictionaryHomophony; } public String getDictionarySource() { return dictionarySource; } public void setDictionarySource(String dictionarySource) { this.dictionarySource = dictionarySource; } public String getDictionaryNote() { return dictionaryNote; } public void setDictionaryNote(String dictionaryNote) { this.dictionaryNote = dictionaryNote; } public String getDictionaryWb() { return dictionaryWb; } public void setDictionaryWb(String dictionaryWb) { this.dictionaryWb = dictionaryWb; } public boolean isBolUpdate() { return bolUpdate; } public void setBolUpdate(boolean bolUpdate) { this.bolUpdate = bolUpdate; } public String getDictionaryAimKind() { return dictionaryAimKind; } public void setDictionaryAimKind(String dictionaryAimKind) { this.dictionaryAimKind = dictionaryAimKind; } public String getDictionaryAimDetail() { return dictionaryAimDetail; } public void setDictionaryAimDetail(String dictionaryAimDetail) { this.dictionaryAimDetail = dictionaryAimDetail; } public String getDictionaryAimCode() { return dictionaryAimCode; } public void setDictionaryAimCode(String dictionaryAimCode) { this.dictionaryAimCode = dictionaryAimCode; } public String getAimSql() { return aimSql; } public void setAimSql(String aimSql) { this.aimSql = aimSql; } }

 

AddDictionaryPanel.xhml

 

<jsfext:javascript path="/cn/hnisi/gdrk/sys/zdgl/zdtm/js/DictionaryFilter.js" /> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 目标字典类型: </td> <td> <jsfext:selectOneMenuEx2 id="mbzdlx" kind="AllKind" tabindex="8" style="width:230px" detail="#{dictionaryModel.dictionaryAimKind}" maxlength="50" valuefield="d"> <jsfext:jseventlistener event="onblur" listener="filter_dictionary(this,'mbzdlx','mbzdzwhy');" /> </jsfext:selectOneMenuEx2> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 目标字典代码: </td> <td> <jsfext:selectSql id="mbzdzwhy" sql="#{dictionaryModel.aimSql}" style="width:230px" widthOfDropDown="110" tabindex="9" value="#{dictionaryModel.dictionaryAimCode}" detail="#{dictionaryModel.dictionaryAimDetail}"> </jsfext:selectSql> </td>

 

ModifyDictionaryPanel.xhtml

 

<jsfext:javascript path="/cn/hnisi/gdrk/sys/zdgl/zdlx/js/DictionaryFilter.js" /> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 目标字典类型: </td> <td> <jsfext:selectOneMenuEx2 id="mbzdlx" kind="AllKind" tabindex="9" style="width:230px" disabled="#{dictionaryModel.bolInput}" detail="#{dictionaryModel.dictionary.aimkind}" maxlength="50"> <jsfext:jseventlistener event="onblur" listener="filter_dictionary(this,'mbzdlx','mbzdzwhy');" /> </jsfext:selectOneMenuEx2> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 目标字典代码: </td> <td> <jsfext:selectSql id="mbzdzwhy" sql="#{dictionaryModel.aimSql}" style="width:230px" widthOfDropDown="110" tabindex="10" value="#{dictionaryModel.dictionary.aimcode}" detail="#{dictionaryModel.dictionary.aimdetail}" disabled="#{dictionaryModel.bolInput}"> </jsfext:selectSql> </td>

 

DictionaryFilter.js

 

function filter_Dictionary(){ var functionname =""; functionname = eval("inputSelectionObject_"+arguments[2]); var kindValue = document.getElementById("allKind").value; var oldSql=""; if(kindValue!="")oldsql="select code as code, detail as detail ,'' as spell from T_SYS_DICTIONARY where scbz='0' and kind = '"+kindValue+"'"; functionname.setSql(oldsql); functionname.reBuild(); }

你可能感兴趣的:(Hibernate,String,function,filter,null,Dictionary)