使用EL访问继承的属性/方法时出错

时间:2010-07-18 23:11:12

标签: java generics jsf tree richfaces

我正在尝试使用通用树后备bean。我有一个名为ACLTree的泛型类,然后是它的一个实现。 在我的JSF文档中,我尝试按#{mybackingbean.property}访问一个值。 但是我得到了一个ELException:

javax.el.ELException: /modules/useradmin/acl.xhtml @30,55 value="#{ACOTree.root}": java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class de.xy.jsf.beans.ACLTree with modifiers "public"

我对泛型和反射api的概念不太熟悉,所以也许根本不可能。

堆栈跟踪:

javax.faces.FacesException: javax.el.ELException: /modules/useradmin/rights.xhtml @30,55 value="#{ACOTree.root}": java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class de.xy.jsf.beans.ACLTree with modifiers "public"
        at javax.faces.component.UIData.getValue(UIData.java:580)
        at org.ajax4jsf.component.UIDataAdaptorBase.getValue(UIDataAdaptorBase.java:1647)
        at org.richfaces.component.UITree.createDataModel(UITree.java:679)
        at org.ajax4jsf.component.UIDataAdaptorBase.getExtendedDataModel(UIDataAdaptorBase.java:621)
        at org.ajax4jsf.component.UIDataAdaptorBase.setRowKey(UIDataAdaptorBase.java:339)
        at org.richfaces.renderkit.TreeRendererBase.writeContent(TreeRendererBase.java:688)
        at org.richfaces.renderkit.TreeRendererBase.encodeChildren(TreeRendererBase.java:629)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
        at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)
        at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)
        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:233)
        at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:270)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:883)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:279)
        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
        at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:149)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
        at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:266)
        at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:261)
        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:827)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:883)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
        at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:578)
        at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
        at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:266)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:159)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
        at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
        at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at cz.softeu.rewriter.RewriterFilter.doFilter(RewriterFilter.java:144)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:636)
Caused by: javax.el.ELException: /modules/useradmin/rights.xhtml @30,55 value="#{ACOTree.root}": java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class de.christianvette.boombox.jsf.beans.ACLTree with modifiers "public"
        at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
        at javax.faces.component.UIData.getValue(UIData.java:577)
        ... 75 more
Caused by: java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class de.xy.jsf.beans.ACLTree with modifiers "public"
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
        at java.lang.reflect.Method.invoke(Method.java:607)
        at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:58)
        at com.sun.el.parser.AstValue.getValue(Unknown Source)
        at com.sun.el.ValueExpressionImpl.getValue(Unknown Source)
        at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
        ... 76 more

通用类:

abstract class ACLTree<T>{
private static final Logger log = Logger.getLogger(ACLTree.class);

public TreeNodeImpl<NodeData> root = null;
public TreeNodeImpl<NodeData> nodes = new TreeNodeImpl<NodeData>();

public ACLTree() {
    log.debug("constructor of generic class");
}

public TreeNodeImpl<NodeData> getNodes() {
    return nodes;
}

public void setNodes(TreeNodeImpl<NodeData> nodes) {
    this.nodes = nodes;
}

public TreeNodeImpl<NodeData> getRoot() {
    log.debug("Entering getRoot()");
    if(root == null) buildTree();
    return root;
}

public void setRoot(TreeNodeImpl root) {
    this.root = root;
}

public TreeNodeImpl createTreeNode(ACLObject item) {

}

abstract Collection<T> getData();

}

实现:

public class ACOTree extends ACLTree<ACO>{

    @Override
    public Collection<ACO> getData() {
         return AclManagerImpl.getInstance().getAllACOs();
    }
}

1 个答案:

答案 0 :(得分:10)

我自己遇到了这个问题。问题是抽象类的声明必须是公开的。

例如:

public abstract class ACLTree<T>{...}

这是因为虽然抽象类的方法可能是公开的,但是除非该类被标记为public,否则不能从其包外部访问它。