J2EE 自定义标签管理按钮权限

7 篇文章 0 订阅
5 篇文章 0 订阅
自定义jsp标签管理按钮权限
1:自定入jsp标签,放入WEB-INF下,标签名为:buttonPower.tld

<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>buttonPower core library</description>
<display-name>buttonPower core</display-name>
<tlib-version>1.1</tlib-version>
<short-name>centfor</short-name>
<uri>http://www.asia-home.com.cn/buttonPower</uri>
<tag>
<description>按钮参数</description>
<name>buttonList</name>
<tag-class>com.asia.home.cn.web.tag.power.ButtonTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>bindPowerName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>



2:ButtonTag 标签类
package com.asia.home.cn.web.tag.power;

import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

import com.asia.home.cn.base.BaseEnvironment;
import com.asia.home.cn.buttonManage.ButtonManage;
import com.asia.home.cn.services.buttonManage.IButtonManageService;

public class ButtonTag extends TagSupport {

private static final long serialVersionUID = 1L;
private IButtonManageService buttonService;
Logger InfoLogger = Logger.getLogger("loginfo");
private String bindPowerName;

protected void init() {
if(buttonService == null){
ApplicationContext applicationContext = BaseEnvironment.getApplicationContext();
buttonService = (IButtonManageService) applicationContext.getBean("buttonService");
}
}
@Override
public int doStartTag() throws JspException {
init();
try {
String fsRightId = queryUserButtonPower(bindPowerName);
ButtonManage buttonParam = null;
if(fsRightId!=null){
buttonParam = buttonService.queryButtonByPowerId(fsRightId);
}
if (buttonParam==null) {
pageContext.getRequest().setAttribute("flag", 0);
return EVAL_BODY_INCLUDE;
}
pageContext.getRequest().setAttribute("buttonParam", buttonParam);
} catch (Exception e) {
InfoLogger.info("ActionTag:" + e);
pageContext.getRequest().setAttribute("flag", 0);
return SKIP_BODY;
}
return EVAL_BODY_INCLUDE;
}

public String queryUserButtonPower(String bindPowerName){
List<Object[]> array = (List<Object[]>)pageContext.getSession().getAttribute("rightArray");
String powerId = null;
for(int i=0;i< array.size();i++){
Object[] temp = array.get(i);
//假如用户权限中父节点为“按纽管理”ID,则加按钮管理查询权限
if("8a80807a-3b72-e40f-013b-7364c2150804".equals(temp[2])&&bindPowerName.equals(temp[1])){
powerId = temp[0].toString();
}
}
return powerId;
}

@Override
public int doAfterBody() throws JspException {
return super.doAfterBody();
}
public String getBindPowerName() {
return bindPowerName;
}
public void setBindPowerName(String bindPowerName) {
this.bindPowerName = bindPowerName;
}

}



3:标签的使用。jsp页面
<%@ page language="java" import="java.net.URLDecoder" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="buttonPower" uri="http://www.asia-home.com.cn/buttonPower"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>"/>
<title>按钮权限使用方法</title>
<script type="text/javascript" src="skin/js/jquery.min.js"></script>
<script type="text/javascript" src="skin/js/oa_month.js"></script>
<LINK href="skin/css/oa.css" type=text/css rel=stylesheet></LINK>
<script type="text/javascript">

function del(){
alert("tt");
}
</script>
</head>
<body>
<div class="main" style=" height:100%">
<div id="add_role">
<div id="box_content">
<div id="box-title"><h2>按钮权限使用方法</h2></div>
<table width="500" height="180" class="public_table" border="0" style="border-collapse:collapse; ">
<tr>
<td colspan="3">&nbsp;&nbsp;&nbsp;
<buttonPower:buttonList bindPowerName ="test页面按钮">
<c:if test ="${flag!=0}">
<input type="button" id="test" οnclick="${buttonParam.onclickMethod}" value="${buttonParam.buttonName}"></input>
</c:if>
</buttonPower:buttonList>
</td>
</tr>
</table>
</div>
</div>
<div id="clear"></div>
</div>


</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值