[英]JSF backing bean can't access the override method of the nested class
我正在使用jsf1.2 XHTML,如下所示:
<h:commandLink label="Open" action="#{surveySubFmTreeViListWeb.dtw.updatePage}">
那么辅助bean看起来像:
public class SurveySubFmTreeViListWeb
{
.....
private DataTableWeb<Entity> dtw = new DataTableWeb<Entity>(Entity.class) {
@Override
public void updatePage() throws Exception
{...snip...}
};
}
如果我重写Class DataTableWeb的public方法,它是backing bean的嵌套类。 我将得到以下异常:
java.lang.IllegalAccessException: Class org.apache.el.parser.AstValue can not access a member of class com.ss.survey.web.SurveySubFmTreeViListWeb $1 with modifiers "public"
但是,如果未在后备bean中重写对public方法的访问,它将可以正常工作。
谁能帮我解决这个问题? 任何帮助表示赞赏。
这是反思的普遍问题。 它的访问控制仅允许语言本身允许的子集。 基本上,为了使反射起作用,您需要将所有内容公开。
在您的情况下,您需要将dtw
初始值设定项dtw
非匿名公共类,如下所示:
private DataTableWeb<Entity> dtw = new CustomDataTableWeb ();
public static class CustomDataTableWeb extends DataTableWeb <Entity>
{
@Override
public void updatePage() throws Exception
{...snip...}
};
如果您需要访问外部this
,请不要忘记从类定义中删除static
。
再次谢谢你。 我可以将其视为以下内容吗
what's happening behind the scenes:
action="#{surveySubFmTreeViListWeb.dtw.updatePage}"
public static void main(String[] args) throws Exception {
Object dtw = SurveySubFmTreeViListWeb.getClass().getDeclaredMethod("getDtw", null).invoke(surveySubFmTreeViListWeb, null);
Object action = dtw .getClass().getDeclaredMethod("updatePage",null).invoke(dtw , 0);
}
因为我有对对象dtw的引用,所以反射可以访问dtw的公共方法。 但是,如果我在Class surveySubFmTreeViListWeb类中重写了一些公共方法,则由于访问受限而导致反射不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.