JSTL标签的问题(尚学堂OA项目开发阶段)
我在开发项目的时候碰到了自定义标签的问题。。。如下
我用了struts2 hibernate annotation spring框架
[color=#FF0000]SecurityFunction是为了实现标签的 hasPermisson功能[/color]
[code=Java]
@Component( "SecurityFunction ")
public class SecurityFunction {
private static AclService aclService;
@Resource(name = "AclService ")
public void setAclService(AclService aclService) {
SecurityFunction.aclService = aclService;
}
public static boolean hasPermisson(int userId, String resourceSn,
int permission) {
System.err.println( "AclService " + aclService == null);
return aclService.hasPermissonByResourceSn(userId, resourceSn,
permission);
}
}
[color=#FF0000]自定义的tld文件[/color]
<?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 ">
<tlib-version> 1.0 </tlib-version>
<short-name> my </short-name>
<uri> http://www.yxx.com/myFunctions </uri>
<function>
<name> hasPermisson </name>
<function-class> com.yxx.oa.SecurityFunction </function-class>
<function-signature> boolean hasPermisson(int, java.lang.String,int) </function-signature>
</function>
</taglib>
在/WEB-INF/web.xml/里面配置
<jsp-config>
<taglib>
<taglib-uri> http://www.yxx.com/myFunctions </taglib-uri>
<taglib-location> /WEB-INF/my.tld </taglib-location>
</taglib>
</jsp-config>
在jsp页面里
添加了语句
<c:if test= "${my.hasPermission(1, 'person ',3) } ">
<a href= "# " onclick= "del( 'person!delete&id=${person.id } '); "> 删除 </a>
</c:if>
[/code]
<c:if test= "${my.hasPermission(1, 'person ',3) } "> 这个方法一直起不了作用 ,我有测试了一下
< c:if test= "${ null eq my.hasPermission(1, 'person ',3) } "> 发现这个my.hasPermission(1, 'person ',3)为空
网盘里面有打包的项目 http://dl.vmall.com/c0joerqhaf
------解决方案--------------------
本人感觉:
先判断aclService是否为空,
System.err.println( "AclService " + aclService == null);
他的具体内容。我估计为空
如果为空的原因如下:
1.在加载内容方面的顺序问题。
a.自定义标签的加载比spring要早
b.所以IOC是没有用的