【JSF】Richfaces复选框树(Checkboxtree)的权限分配的解决方案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

【JSF】Richfaces复选框树(Checkboxtree)的权限分配的解决方案应大家要求,在此帖上效果图:设计信息系统的时候,往往要设计一套用户管理模块,其中就会牵扯到角色权限的分配,在Richfaces中可以使用PickList来进行角色的分配,但权限的分配不好使用这个控件,因为权限有时候根据父子模块来分配,那么就要分级,而PickList不带分级功能,这时候我们就需要一个Checkboxtree来满足我们的需要。Checkboxtree的页面代码:rich:treeswitchType=clientvalue=#{user.privilegeTree}var=itemselectedClass=selectedNoderich:treeNodehighlightedClass=treeLinkh:selectBooleanCheckboxvalue=#{item.selected}/h:selectBooleanCheckboxh:outputTextvalue=#{item.name}//rich:treeNode/rich:tree页面用到的js代码,(注意:如果页面中有其他的checkbox,这段代码需要进行修改):scripttype=text/javascriptsrc=%=basePath%pages/js/jquery.js/scriptscripttype=text/javascriptjQuery.noConflict();//与JSF搭配需要这句话,不然会有冲突jQuery(document).ready(function(){//Addclickeventlistenertoeachcheckboxinthetreepage//Note!Usingthissimpleselectorassumesthattherearenoother//checkboxesonthepage,ifthereareothercheckboxesthen//selectorshouldbechangedjQuery(:checkbox).click(function(){updateChildren(this);});});/scriptscripttype=text/javascriptfunctionupdateChildren(currentCheckBox){//Getstateofcurrentcheckbox(trueorfalse)varstate=currentCheckBox.checked;//GetparentTABLE,wherecurrentcheckboxisplacesvarparentTables=jQuery(currentCheckBox).parents(table);varparentTable=parentTables[0];//GetDIVwherechildnodeswithcheckboxesaresituated//See()andnext()varchildDivs=jQuery(parentTable).next(div);varchildDiv=childDivs[0];//Iterateoverallchildnodescheckboxesandsetsamestateasthe//currentcheckboxstatejQuery(childDiv).contents().find(:checkbox).each(function(){this.checked=state;});}/script这样页面部分就完成了,下面是后台处理的代码。User当中的代码:publicPrivilegeTreeNodegetPrivilegeTree(){try{if(privilegeTree==null)privilegeTree=newPrivilegeTree();returnprivilegeTree.getPrivilegeRootNode();}catch(Exceptione){info(获得权限树出错,e);returnnull;}}权限树代码:publicclassPrivilegeTree{privatestaticintroot=0;//根节点的父编号privatePrivilegeTreeNodeprivilegeRootNode=null;publicPrivilegeTreeNodegetPrivilegeRootNode(){if(privilegeRootNode==null){privilegeRootNode=newPrivilegeTreeNode(root);privilegeRootNode.setId(0);privilegeRootNode.setName(角色权限);}returnprivilegeRootNode;}}树节点的代码:publicclassPrivilegeTreeNodeimplementsTreeNode{privateintid;privateStringname=null;privateTreeNodeparent=null;privateMapchildren=newHashMap();;privatebooleanselected=false;privateFuncModuleTreeDefDTOfuncModuleTreeDefDTO=null;publicPrivilegeTreeNode(intparent){ListFuncModuleTreeDefDTOlist=WSFactory.getUserManagementBODelegate().getFuncModuleTreeDefsByParentId(parent);if(list!=null){for(FuncModuleTreeDefDTOobj:list){intoId=obj.getFuncModuleTreeDef().getModuleid();PrivilegeTreeNodenode=newPrivilegeTreeNode(oId);node.setParent(this);node.setId(oId);node.setName(obj.getFuncModuleTreeDef().getModuleName());node.setFuncModuleTreeDefDTO(obj);addChild(oId,node);}}}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#addChild(java.lang.Object,org.richfaces.model.TreeNode)*/publicvoidaddChild(Objectkey,TreeNodetn){children.put(key,tn);}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#getChild(java.lang.Object)*/publicTreeNodegetChild(Objectkey){//TODOAuto-generatedmethodstubif(children!=null)return(TreeNode)children.get(key);returnnull;}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#getChildren()*/publicIteratorgetChildren(){if(children!=null)returnchildren.entrySet().iterator();returnnull;}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#getData()*/publicObjectgetData(){//TODOAuto-generatedmethodstubreturnthis;}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#getParent()*/publicTreeNodegetParent(){returnthis.parent;}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#isLeaf()*/publicbooleanisLeaf(){if(children==null||children.isEmpty())returntrue;returnfalse;}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#removeChild(java.lang.Object)*/publicvoidremoveChild(Objectkey){if(children!=null)children.remove(key);}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#setData(java.lang.Object)*/publicvoidsetData(Objectdata){}/*(non-Javadoc)*@seeorg.richfaces.model.TreeNode#setParent(org.richfaces.model.TreeNode)*/publicvoidsetParent(TreeNodeparent){//TODOAuto-generatedmethodstubthis.parent=parent;}publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicbooleanisSelected(){returnselected;}publicvoidsetSelected(booleanselected){this.selected=selected;}publicvoidsetChildren(Mapchildren){this.children=children;}publicFuncModuleTreeDefDTOgetFuncModuleTreeDefDTO(){returnfuncModuleTreeDefDTO;}publicvoidsetFuncModuleTreeDefDTO(FuncModuleTreeDefDTOfuncModuleTreeDefDTO){this.funcModuleTreeDefDTO=funcModuleTreeDefDTO;}}User中,获取用户选定值得代码:此为递归函数,需要在其他业务逻辑中调用/***获得所有被选择权限的列表**@paramlist*PrivRoleMainDefDTO的权限列表*@paramnode*从哪个树获取*@paramgregorianCalendarDate*当前时间*@paramuserid*当前用户id*@paramroleId*相关角色id*/privatevoidgetPrivRoleDetailDefDTOs(ListPrivRoleDetailDefDTOlist,PrivilegeTreeNodenode,XMLGregorianCalendargregorianCalendarDate,Integeruserid,

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功