增加字典条目界面:
<ui:component> <jsfext:javascript path="/cn/hnisi/gdrk/sys/zdgl/zdtm/js/Validation.js" /> <jsfext:defaultFocusedElement value="zwhy" /> <h:form> <t:saveState value="#{dictionaryModel}" /> <fieldset align="center" style="width: 800; height: 200; border: 1px solid blue; margin: 0px; padding: 0px;"> <legend> <span style="font-size: 10pt; font-weight: bold; color: black" mce_style="font-size: 10pt; font-weight: bold; color: black">字典类型信息</span> </legend> <table width="90%" align="center" border="0"> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 类型: </td> <td> <jsfext:outputText value="#{dictionaryModel.dictionary.kind}" id="lx" style="width:200px" maxlength="50" /> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 字典代码: </td> <td> <jsfext:inputText id="dm" size="35" tabindex="4" value="#{dictionaryModel.dictionaryCode}" required="true" cnName="字典条目代码" maxlength="50"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> <h:message for="dm"></h:message> </td> </tr> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 中文含义: </td> <td> <jsfext:inputText id="zwhy" size="35" tabindex="1" value="#{dictionaryModel.dictionaryDetail}" required="true" cnName="字典条目中文含义" maxlength="85"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 拼音头: </td> <td> <jsfext:inputText id="py" size="35" tabindex="5" value="#{dictionaryModel.dictionarySpell}" maxlength="256"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> </tr> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 同音: </td> <td> <jsfext:inputText id="hpy" size="35" tabindex="2" value="#{dictionaryModel.dictionaryHomophony}" maxlength="256"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 五笔: </td> <td> <jsfext:inputText id="wb" size="35" tabindex="6" value="#{dictionaryModel.dictionaryWb}" maxlength="128"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> </tr> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 来源: </td> <td> <jsfext:selectOneMenuEx2 id="ly" kind="LY" tabindex="3" style="width:166px" value="#{dictionaryModel.dictionarySource}" maxlength="128"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:selectOneMenuEx2> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 说明: </td> <td> <jsfext:inputText id="sm" size="35" tabindex="7" value="#{dictionaryModel.dictionaryNote}" maxlength="128"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <t:inputHidden value="save" id="saveFlag" forceId="true" /> </tr> </table> <div align="center"> <h:commandButton tabindex="8" value=" 保 存 " action="#{dictionaryModel.onMainFormSubmit}" onclick="return check()"> </h:commandButton> </div> </fieldset> </h:form> </ui:component>
修改字典条目界面:
<ui:component> <jsfext:defaultFocusedElement value="zwhy" /> <jsfext:javascript path="/cn/hnisi/gdrk/sys/zdgl/zdtm/js/Validation.js" /> <h:form> <t:saveState value="#{dictionaryModel}" /> <fieldset align="center" style="width: 800; height: 200; border: 1px solid blue; margin: 0px; padding: 0px;"> <legend> <span style="font-size: 10pt; font-weight: bold; color: black" mce_style="font-size: 10pt; font-weight: bold; color: black">字典类型信息</span> </legend> <table width="90%" align="center" border="0"> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 类型: </td> <td> <jsfext:outputText value="#{dictionaryModel.dictionary.kind}" id="lx" style="width:200px" maxlength="50" /> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 字典代码: </td> <td> <jsfext:inputText id="dm" size="35" tabindex="4" value="#{dictionaryModel.dictionary.code}" required="true" cnName="字典条目代码" disabled="#{dictionaryModel.bolInput}" maxlength="50"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> </tr> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 中文含义: </td> <td> <jsfext:inputText id="zwhy" size="35" tabindex="1" value="#{dictionaryModel.dictionary.detail}" required="true" cnName="字典条目中文含义" disabled="#{dictionaryModel.bolInput}" maxlength="85"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 拼音头: </td> <td> <jsfext:inputText id="px" size="35" tabindex="5" value="#{dictionaryModel.dictionary.spell}" disabled="#{dictionaryModel.bolInput}" maxlength="256"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> </tr> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 同音: </td> <td> <jsfext:inputText id="hpy" size="35" tabindex="2" value="#{dictionaryModel.dictionary.homophony}" disabled="#{dictionaryModel.bolInput}" maxlength="256"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 五笔: </td> <td> <jsfext:inputText id="wb" size="35" tabindex="6" value="#{dictionaryModel.dictionary.wb}" disabled="#{dictionaryModel.bolInput}" maxlength="128"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> </tr> <tr> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 来源: </td> <td> <jsfext:selectOneMenuEx2 id="ly" kind="LY" tabindex="3" style="width:166px" value="#{dictionaryModel.dictionary.source}" disabled="#{dictionaryModel.bolInput}" maxlength="128"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:selectOneMenuEx2> </td> <td align="right" style="font-size: 10pt" mce_style="font-size: 10pt"> 说明: </td> <td> <jsfext:inputText id="sm" size="35" tabindex="7" value="#{dictionaryModel.dictionary.note}" disabled="#{dictionaryModel.bolInput}" maxlength="128"> <jsfext:jseventlistener event="onkeydown" listener="convertEnter2Tab()" /> </jsfext:inputText> </td> <t:inputHidden value="update" id="saveFlag" forceId="true" /> </tr> </table> <div align="center"> <h:commandButton tabindex="8" value=" 修 改 " id="Modify" disabled="#{dictionaryModel.bolModify}" action="#{dictionaryModel.changeFlag}" immediate="true"> </h:commandButton> <h:commandButton tabindex="9" value=" 保 存 " id="Save" action="#{dictionaryModel.onMainFormSubmit}" disabled="#{dictionaryModel.bolSave}" onclick="return check()" /> <h:commandButton tabindex="10" value=" 取 消 " id="Cancel" action="#{dictionaryModel.recover}" disabled="#{dictionaryModel.bolCancel}"> </h:commandButton> </div> </fieldset> </h:form> </ui:component>
增加和修改方法:
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 errorStr = null; 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 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()); 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(dictionary.getCode(), 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; } 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; }