I need to check a property in the javax.faces.com ponent.html.Htm lInputText.
If i do it in the following manner,I get things fine:
if(comp.getClas s().getName().e qualsIgnoreCase ("javax.faces.c omponent.html.H tmlInputText")) {
String getter=((javax. faces.component .html.HtmlInput Text)comp).getO nfocus();
if(getter!=null ) {
System.out.prin tln(getter);
}
}
But if i invoke it through reflection,I get nothing.
I am doing the following:
Class reqClass = Class.forName(" javax.faces.com ponent.html.Htm lInputText");
Method[] methodList = reqClass.getDec laredMethods();
int methodIdx = 0;
for (int i = 0; i < methodList.leng th; i++) {
Method reqMethod =methodList[i];
if(reqMethod.ge tName().indexOf ("getOn")== 0) //method starts with getOn
{
// method accepts parameters, define the types in order here as Class[]
Class[] classParams = new Class [] {};
// set the method of the class object
Method method = reqClass.getMet hod( reqMethod.getNa me(), classParams );
// pass values to fill parameters of method
Object[] arguments = new Object [] {};
// invoke method via reflection.Note that class has default constructor
Object retobj=method.i nvoke( reqClass.newIns tance() ,
arguments );
String getterResult = (String)retobj;
if(getterResult !=null)
{
System.out.prin tln(reqMethod.g etName() + " ## " + getterResult);
}
}
}
What am i doing wrong while invoking the method through reflection.
I get no exception either.
If i do it in the following manner,I get things fine:
if(comp.getClas s().getName().e qualsIgnoreCase ("javax.faces.c omponent.html.H tmlInputText")) {
String getter=((javax. faces.component .html.HtmlInput Text)comp).getO nfocus();
if(getter!=null ) {
System.out.prin tln(getter);
}
}
But if i invoke it through reflection,I get nothing.
I am doing the following:
Class reqClass = Class.forName(" javax.faces.com ponent.html.Htm lInputText");
Method[] methodList = reqClass.getDec laredMethods();
int methodIdx = 0;
for (int i = 0; i < methodList.leng th; i++) {
Method reqMethod =methodList[i];
if(reqMethod.ge tName().indexOf ("getOn")== 0) //method starts with getOn
{
// method accepts parameters, define the types in order here as Class[]
Class[] classParams = new Class [] {};
// set the method of the class object
Method method = reqClass.getMet hod( reqMethod.getNa me(), classParams );
// pass values to fill parameters of method
Object[] arguments = new Object [] {};
// invoke method via reflection.Note that class has default constructor
Object retobj=method.i nvoke( reqClass.newIns tance() ,
arguments );
String getterResult = (String)retobj;
if(getterResult !=null)
{
System.out.prin tln(reqMethod.g etName() + " ## " + getterResult);
}
}
}
What am i doing wrong while invoking the method through reflection.
I get no exception either.