I have a very strange situation.
I get the following arguments from my Bean
:
#{segurancaBean.callSubAcaoMethod(subAcao, moduloBean.class.name, modulo.id)}
This method is dynamic:
public void callSubAcaoMethod(Acao acao, String bean, Long id){
try {
Class<?> clazz = Class.forName(bean);
Method method = clazz.getMethod(acao.getTipoAcao().getNmBean(), Long.class);
Object obj = clazz.newInstance();
Object ins = new Object();
ins = method.invoke(obj, id);
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
Logger.getLogger(SegurancaBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
Of this method I will receive:
Name of my generic method
Name of my class for dynamic instance
ID of the object to come from view
And below is the method that will be used:
@Override
public void btnAlterar(Long id){
Modulo m = new Modulo();
m = moduloServico.pesquisar(id);
}
Now comes the strange part.
If in this my method or put a System.out.println("alguma mensagem")
or Modulo m = new Modulo();
or print on the screen the ID I get from parameter works normally!
Now when I'm going to do any operation related to instantiating an object, I have the error:
java.lang.reflect.InvocationTargetException
The m = moduloServico.pesquisar(id);
line is an example that generates this error.
In detail, I also put in my view
a direct button that accesses the method without going through callSubAcaoMethod
and it works normal! I can instantiate and do everything I want, that is, it would not be a problem of my service.