OA project permission design ③

Source: Internet
Author: User

1. next, in the previous article, we wrote the basic requirements and added the echo data method, we need to know that all the objects passed on the page are the names of the objects corresponding to the ID. To echo, we need to get the privilegeids. If we use checkbox as shown in the previous article in JSP, although it can be displayed, it is not easy to wrap the line, and it is difficult to display the tree structure. Therefore, we can improve the functionality by writing a piece of code in JSP. the JSP code of the Code is as follows:

<% @ Page Language = "Java" Import = "Java. util. * "pageencoding =" UTF-8 "%> <HTML> Explanation: red indicates improved code.

① The first step is to use the struts2 label to iterate the privilegelist, because we put it in the map in the background, so adding a # in front of it means to retrieve it from the map.

② Then write the commonly used input checkbox label to dynamically display the name to be displayed. The label Label is used to achieve the function that can also be selected by clicking the name, why must I write the ID as Cb _ $ {ID} because the ID must change once in a loop? You cannot add a dynamic ID to CB to achieve the same effect as clicking the name.

③ Then, the value in the input tag is placed with ID, which corresponds to the listkey of the checkboxlist, and the name below corresponds to the listvalue, the above name corresponds to the name of checkboxlist and the struts2 tag added to the input. Because it is explained on the server side, we only see the result on the page, this attribute is used to determine whether the current ID exists in all permission IDs. If it exists, the returned value is null if it does not exist, if there is any, it will be displayed in front of the page, that is, there is a check mark, because when we set the permission, we click it to indicate that it is the ID of the previous permission, then save it to the database. Therefore, you only need to compare and select the checked attribute to implement the echo function.

④ After improvement, the effect is as follows:


2. Provide the final code for background improvement:

Roleaction

Package COM. ICSS. oa. view. action; import Java. util. hashset; import Java. util. list; import javax. annotation. resource; import Org. springframework. context. annotation. scope; import Org. springframework. stereotype. controller; import COM. ICSS. oa. base. baseaction; import COM. ICSS. oa. domain. privilege; import COM. ICSS. oa. domain. role; import COM. ICSS. oa. service. privilegeservice; import COM. ICSS. oa. service. roleservice; import COM. opensymphony. xwork2.actioncontext; import COM. opensymphony. xwork2.actionsupport; import COM. opensymphony. xwork2.modeldriven; @ suppresswarnings ("serial") @ controller @ scope ("prototype") public class roleaction extends baseaction <role> {private long [] privilegeids; public long [] getprivilegeids () {return privilegeids;} public void setprivilegeids (long [] privilegeids) {This. privilegeids = privilegeids;} // list method Public String list () throws exception {list <role> rolelist = roleservice. findall (); actioncontext. getcontext (). put ("rolelist", rolelist); Return "list" ;}// Delete method Public String Delete () throws exception {roleservice. delete (model. GETID (); Return "tolist" ;}// Add the Public String addui () throws exception {return "addui" ;}// Add the Public String add () method () throws exception {// set the page parameter value // role = new role (); // role. setname (role. getname (); // role. setdescription (role. getdescription (); // save it to the database roleservice. save (model); Return "tolist";} // modify the PAGE method Public String editui () throws exception {// obtain a message about the role object based on the ID and display role role1 = roleservice. getbyid (model. GETID (); // display data on the Edit page // This. name = role. getname (); // This. description = role. getdescription (); actioncontext. getcontext (). getvaluestack (). push (role1); Return "editui";} // modify the public string edit () throws exception {// set the value of role role2 = roleservice. getbyid (model. GETID (); role2.setname (model. getname (); role2.setdescription (model. getdescription (); // update to the roleservice in the database. update (role2); Return "tolist";} // set the permission PAGE method Public String setprivilegeui () throws exception {// prepare the displayed data role = roleservice. getbyid (model. GETID (); actioncontext. getcontext (). put ("role", role); List <privilege> privilegelist = privilegeservice. findall (); actioncontext. getcontext (). put ("privilegelist", privilegelist); // prepare the echo data privilegeids = new long [role. getprivileges (). size ()]; int Index = 0; For (privilege: role. getprivileges () {privilegeids [index ++] = privilege. GETID ();} return "setprivilegeui";} // permission setting method Public String setprivilege () throws exception {// retrieve the source object role = roleservice from the database. getbyid (model. GETID (); // set the attribute list to be modified <privilege> privileges = privilegeservice. getbyids (privilegeids); role. setprivileges (New hashset <privilege> (privileges); // update it to the roleservice in the database. update (role); Return "tolist ";}}
3. The tree structure notes will be given tomorrow. Specifically, they will be implemented using jquery's official General Treeview.


OA project permission design ③

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.