• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamically loading class  RSS feed

 
Reshma Reddy
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to load one class dynamically in jsf, it has been configured in faces-config.xml. In java class I am able to get this file in runtime, but at the time of running my test cases it is not able to get dynamically I am getting nullpointer Exception.



Can any one tell me how load a class file dynamically.

Regards,
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In web applications, servlet container loads the classes, you create instances of the classes and use them.
As for your problem, make sure you are creating an instance of the class.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vardhan reddy wrote:Hi All,

I want to load one class dynamically in jsf, it has been configured in faces-config.xml. In java class I am able to get this file in runtime, but at the time of running my test cases it is not able to get dynamically I am getting nullpointer Exception.



Can any one tell me how load a class file dynamically.

Regards,


What does your getManagedBean() method look like? If it makes use of FacesContext in anyway, you'll only be able to use it during a JSF request.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the big advantages of JSF is that it's a lot easier to unit-test JSF backing beans than their corresponding structures in other frameworks.

However, when you're running a stand-alone JUnit, the JSF web framework isn't available. If you want a bean to be instantiated - whether it's a managed bean or an unmanaged bean - you have to explicitly instantiate it. Just do a "new ABCBean()".
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry completely missed the 'test' word!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!