action 수신 강력한 디자인 기능, 페이지 인자 왜 모두 위해 "on '

jsp java struts 질문: edit.jsp 페이지 실행 save 때 selectoper[] 수신 부분function.FunctionCode파라미터 값 을 'on' 주로 function.ParentCode 뒤에 연결되어 있다function.FunctionCode.

강력한 디자인 기능, 페이지 코드는 edit.jsp:

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<table cellSpacing="1" cellPadding="0" width="90%" align="center" bgColor="#f5fafe" border="0">
<tr>
<td>
<fieldset style="width:100%; border : 1px solid #73C8F9;text-align:left;COLOR:#023726;FONT-SIZE: 12px;"><legend align="left">권한 분배하다</legend>

<table cellSpacing="0" cellPadding="0" width="90%" align="center" bgColor="#f5fafe" border="0">
<tr>
<td class="ta_01" colspan=2 align="left" width="100%" >
<s:set value="%{''}" var="ParentCode" scope="request"/>
<s:iterator value="roleRightsList" var="function">
<s:if test="%{#request.ParentCode==#function.ParentCode}">
<s:if test="#function.flag==1">
<input type="checkbox" name="selectoper" value="#function.FunctionCode" checked/>
<s:property value="#function.FunctionCode"/>
</s:if>
<s:else>
<input type="checkbox" name="selectoper" value="#function.FunctionCode" />
<s:property value="#function.FunctionCode"/>
</s:else>
<s:property value="#function.FunctionName"/>&nbsp;&nbsp;&nbsp;
</s:if>
<s:else><br>
<s:iterator begin="0" end="%{8-#function.ParentName.length()}" step="1">
&nbsp;&nbsp;&nbsp;
</s:iterator>
<s:property value="#function.ParentName"/> :
<s:if test="#function.flag==1">
<input type="checkbox" name="selectoper" value="#function.FunctionCode" checked/>
</s:if>
<s:else>
<input type="checkbox" name="selectoper" />
<s:property value="#function.FunctionCode"/>
</s:else>
<s:property value="#function.FunctionName"/>&nbsp;&nbsp;&nbsp;
<s:set value="#function.ParentCode" var="ParentCode" scope="request"/>
</s:else>
</s:iterator>
</td>
</tr>
<input type="hidden" name="roleID" >
</table>
<br>
</fieldset>
</td>
</tr>

</table>
까지

글쓴이 유진 작성일 2015-01-20 13:12

action 페이지 코드는:

package com.lv.elec.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.lv.elec.service.ElecRoleService;
import com.lv.elec.service.ElecSystemDDlService;
import com.lv.elec.util.XmlObject;
import com.lv.elec.webForm.ElecDataDictionaryForm;
import com.lv.elec.webForm.ElecRoleForm;
import com.lv.elec.webForm.ElecUserForm;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class elecRoleAction extends ActionSupport implements ModelDriven<ElecRoleForm>{

//이용 modeldriven 가져오기 표 속성
private ElecRoleForm roleForm;

//이용 set, get 방법 가져오기 표 속성
private String role;

//이용 request 가져오기 표 속성
/* HttpServletRequest request=ServletActionContext.getRequest();
String roleID=request.getParameter("role");
*/
@Resource(name=ElecRoleService.roleService_NAME)
private ElecRoleService roleService;
// @Resource(name=ElecSystemDDlService.SystemDDlService_NAME)
// private ElecSystemDDlService ddlService;

public String home(){
//권한 목록 가져오기
List<XmlObject> functionList=roleService.getAllRights();
ActionContext.getContext().put("functionList", functionList);
//역할 이름 목록 가져오기
List<ElecRoleForm> roleNamesList=roleService.getAllRoleNames("캐릭터 유형");
//List<ElecDataDictionaryForm> roleNamesList=ddlService.findDDlFormByKeyword("캐릭터 유형");
ActionContext.getContext().put("roleNamesList", roleNamesList);
return "home";
}

public String edit(){


System.out.println(role);
//캐릭터 대응 권한 가져오는 중
List<XmlObject> roleRightsList=roleService.getRoleRights(role);
ActionContext.getContext().put("roleRightsList", roleRightsList);
//사용자 역할 대응 가져오기
List<ElecUserForm> roleUsersList=roleService.getRoleUsers(role);
ActionContext.getContext().put("roleUsersList", roleUsersList);
return "edit";
}

public String save(){
roleService.saveRole(roleForm);
return "save";
}

public ElecRoleForm getModel() {
// TODO Auto-generated method stub
if(roleForm==null){
roleForm=new ElecRoleForm();
}
return roleForm;
}


public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}
}

글쓴이 유진 작성일 2015-01-20 13:40

service 층 코드는:

package com.lv.elec.serviceImpl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.stereotype.Service;

import com.lv.elec.dao.ElecRoleDao;
import com.lv.elec.dao.ElecRoleUserDao;
import com.lv.elec.dao.ElecSystemDDlDao;
import com.lv.elec.model.ElecDataDictionary;
import com.lv.elec.model.ElecRoleRights;
import com.lv.elec.model.ElecUser;
import com.lv.elec.model.ElecUserAndRole;
import com.lv.elec.service.ElecRoleService;
import com.lv.elec.util.XmlObject;
import com.lv.elec.webForm.ElecRoleForm;
import com.lv.elec.webForm.ElecUserForm;

@Service(ElecRoleService.roleService_NAME)
public class ElecRoleServiceImpl implements ElecRoleService {

@Resource(name=ElecSystemDDlDao.SystemDDlDao_NAME)
private ElecSystemDDlDao systemDDlDao;
@Resource(name=ElecRoleDao.roleDao_NAME)
private ElecRoleDao roleDao;
@Resource(name=ElecRoleUserDao.roleUserDaoName)
private ElecRoleUserDao roleUserDao;
//복귀 모든 권한 목록
@SuppressWarnings("unchecked")
@Override
public List<XmlObject> getAllRights(){
List<XmlObject> functionList=new ArrayList<XmlObject>();
SAXReader reader=new SAXReader();
try {
//xml 파일 가져오기 실제 경로
String str=ServletActionContext.getServletContext().getRealPath("/WEB-INF/classes/Function.xml");

Document document=reader.read(str);
Element root=document.getRootElement();//뿌리 노드 가져오기
//은 뿌리 노드 사이를 옮겨다니기 그 자식 노드
for(Iterator<Element> iter=root.elementIterator("Function");iter.hasNext();){
XmlObject function=new XmlObject();
Element element = (Element) iter.next();
function.setFunctionCode(element.elementText("FunctionCode"));
function.setFunctionName(element.elementText("FunctionName"));
function.setParentCode(element.elementText("ParentCode"));
function.setParentName(element.elementText("ParentName"));
functionList.add(function);
}
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return functionList;
}

//복귀 모든 캐릭터 목록
@Override
public List<ElecRoleForm> getAllRoleNames(String keyword){
List<ElecDataDictionary> ddlList=systemDDlDao.findByKeywordAndConditions(keyword, "", "");
List<ElecRoleForm> roleNamesList=new ArrayList<ElecRoleForm>();
for(int i=0;i<ddlList.size();i++){
ElecRoleForm roleForm=new ElecRoleForm();
ElecDataDictionary systemDDl=ddlList.get(i);
roleForm.setRoleID(systemDDl.getDdlCode().toString());
roleForm.setRoleName(systemDDl.getDdlName());
roleNamesList.add(roleForm);
}
return roleNamesList;
}

//복귀 역할 대응 권한
@Override
public List<XmlObject> getRoleRights(String roleID){
ElecRoleRights roleRights=roleDao.findById(roleID);
List<XmlObject> roleRightsList=new ArrayList<XmlObject>();
String rightsCode=null;
if(roleRights!=null){
rightsCode=roleRights.getRightsCode();
}

//먼저 얻은 모든 권한
List<XmlObject> allRightsList=this.getAllRights();
for(int i=0;i<allRightsList.size();i++){
XmlObject function=allRightsList.get(i);
//flag을 0 표시 안 포함 이 권한 을 1 표시 포함 이 권한
function.setFlag("0");
//처음부터 모든 게 더 통해 권한 중 선택 역할 포함된 권한
if(rightsCode!=null&&rightsCode.contains(function.getFunctionCode())){
function.setFlag("1");
}
roleRightsList.add(function);
}
return roleRightsList;
}
//다시 사용자 역할 대응
@Override
public List<ElecUserForm> getRoleUsers(String roleID){
List<Object[]> usersList=roleDao.findUsersByRoleID(roleID);
List<ElecUserForm> usersFormList=new ArrayList<ElecUserForm>();
for(int i=0;usersList!=null&&i<usersList.size();i++){
Object[] user=usersList.get(i);
ElecUserForm userForm=new ElecUserForm();
userForm.setUserID((String) user[0]);
userForm.setLogonName((String) user[1]);
userForm.setUserName((String) user[2]);
userForm.setFlag((String) user[3]);
usersFormList.add(userForm);
}
return usersFormList;
}

//저장 사용자 역할
@Override
public void saveRole(ElecRoleForm roleForm) {
// TODO Auto-generated method stub
String roleID=roleForm.getRoleID();
//저장 캐스팅 권한 방법
String[] selectRights=roleForm.getSelectoper();
String rightCodes="";
for(int i=0;selectRights!=null&&i<selectRights.length;i++){
System.out.println(selectRights[i]);
rightCodes+=selectRights[i];
}
ElecRoleRights roleRights=roleDao.findById(roleID);
if(roleRights!=null){
roleDao.deleteById(roleID);
}
ElecRoleRights roleRights2=new ElecRoleRights();
roleRights2.setRoleID(roleID);
roleRights2.setRightsCode(rightCodes);
roleDao.save(roleRights2);

//저장 역할 사용자 방법
String[] selectUsers=roleForm.getSelectuser();
String userID="";
for(int i=0;selectUsers!=null&&i<selectUsers.length;i++){
userID=selectUsers[i];
ElecUserAndRole userRole=roleUserDao.findById(userID);
if(userRole!=null){
roleUserDao.deleteById(userID);
}
ElecUserAndRole userRole2=new ElecUserAndRole();
userRole2.setRoleID(roleID);
userRole2.setUserID(userID);
roleUserDao.save(userRole2);
}
}

}

글쓴이 유진 작성일 2015-01-20 14:30

xml 파일 코드는:

<?xml version="1.0" encoding="UTF-8"?>

<ElecData>

<Function>
<FunctionCode>a</FunctionCode>
<FunctionName>기기 관리자</FunctionName>
<ParentCode>device</ParentCode>
<ParentName>기술 시설의 보호 관리</ParentName>
</Function>
<Function>
<FunctionCode>b</FunctionCode>
<FunctionName>설비 정비 조정</FunctionName>
<ParentCode>device</ParentCode>
<ParentName>기술 시설의 보호 관리</ParentName>
</Function>
<Function>
<FunctionCode>c</FunctionCode>
<FunctionName>장비 구입 계획</FunctionName>
<ParentCode>device</ParentCode>
<ParentName>기술 시설의 보호 관리</ParentName>
</Function>

<Function>
<FunctionCode>d</FunctionCode>
<FunctionName>도면 관리 자료</FunctionName>
<ParentCode>informationAndPaper</ParentCode>
<ParentName>기술 자료 도면 관리</ParentName>
</Function>

<Function>
<FunctionCode>e</FunctionCode>
<FunctionName>기본 정보 사이트</FunctionName>
<ParentCode>station</ParentCode>
<ParentName>사이트 운영 관리 장치</ParentName>
</Function>
<Function>
<FunctionCode>f</FunctionCode>
<FunctionName>운행 상황을</FunctionName>
<ParentCode>station</ParentCode>
<ParentName>사이트 운영 관리 장치</ParentName>
</Function>
<Function>
<FunctionCode>g</FunctionCode>
<FunctionName>유지 보수 상황</FunctionName>
<ParentCode>station</ParentCode>
<ParentName>사이트 운영 관리 장치</ParentName>
</Function>

<Function>
<FunctionCode>h</FunctionCode>
<FunctionName>모니터 데스크 건축 관리</FunctionName>
<ParentCode>jct</ParentCode>
<ParentName>모니터 데스크 건축 관리</ParentName>
</Function>

<Function>
<FunctionCode>i</FunctionCode>
<FunctionName>역할 관리</FunctionName>
<ParentCode>sysmng</ParentCode>
<ParentName>시스템 관리</ParentName>
</Function>
<Function>
<FunctionCode>j</FunctionCode>
<FunctionName>업무</FunctionName>
<ParentCode>sysmng</ParentCode>
<ParentName>시스템 관리</ParentName>
</Function>
<Function>
<FunctionCode>k</FunctionCode>
<FunctionName>데이터 사전 유지</FunctionName>
<ParentCode>sysmng</ParentCode>
<ParentName>시스템 관리</ParentName>
</Function>

<Function>
<FunctionCode>l</FunctionCode>
<FunctionName>새로운 기능</FunctionName>
<ParentCode>operate</ParentCode>
<ParentName>조작 권한 분배하다</ParentName>
</Function>
<Function>
<FunctionCode>m</FunctionCode>
<FunctionName>삭제 기능 추가</FunctionName>
<ParentCode>operate</ParentCode>
<ParentName>조작 권한 분배하다</ParentName>
</Function>
<Function>
<FunctionCode>n</FunctionCode>
<FunctionName>편집 기능</FunctionName>
<ParentCode>operate</ParentCode>
<ParentName>조작 권한 분배하다</ParentName>
</Function>


</ElecData>

글쓴이 유진 작성일 2015-01-20 16:07

형, 붙어 이렇게 많은 코드?누가 구경 갈 시간 있어요?너는 문제를 것이 좀 말해? ?

글쓴이 Suck 작성일 2015-01-20 16:20