tags:

views:

47

answers:

2

hi all. i'm using jsf1.2 The xhtml as followings:

<h:commandLink label="Open" action="#{surveySubFmTreeViListWeb.dtw.updatePage}">

then the backing bean looks like:

public class SurveySubFmTreeViListWeb 
  { 
    .....
        private DataTableWeb<Entity> dtw = new DataTableWeb<Entity>(Entity.class) {
                @Override
                public void updatePage() throws Exception 
                {...snip...}
        };
  }

if i override the public method of Class DataTableWeb which is the nested class of backing bean. i will get the following exceptions as:

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"

however,if access the public method didn't be override in the backing bean ,it will work out ok.if anyone can help me figure it out ? Any help is appreciated.

+1  A: 

That's a general problem with reflection. Its access control only permits a subset of what language itself permits. Basically, for reflection to work, you need to make everything public.

In your case you need to make dtw initializer a non-anonymous public class, sort of like this:

private DataTableWeb<Entity> dtw = new CustomDataTableWeb ();

public static class CustomDataTableWeb extends DataTableWeb <Entity>
{
    @Override
    public void updatePage() throws Exception 
    {...snip...}
};

If you need access to outer this, don't forget to remove static from class definition.

doublep
Hi,doublep. Thank u so much. But I was still confused at why using the original method updatePage() in Class DataTableWeb can work out ok .
@mark-zhu: Because (I guess) it is defined in a public class. Reflection is different from normal access in that it takes access restriction of the class into account as well. E.g. for normal access "private class but public method" is OK: as long as you have reference to an object, it doesn't matter if you have access to its actual class. But for reflection this won't work, you need the class to be public as well.
doublep
A: 

thank u again . can i take it as followings

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);

}

because i has the reference to the object dtw,so the reflection can access the public method of dtw. but if i override some public method in the Class surveySubFmTreeViListWeb ,the reflection won't work caused by access restricted

do not add answers, but edit your original question
Thorbjørn Ravn Andersen
Thank u doublep. I fix the problem .u r a good man.