Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FaceletFactory.getInstance() returns null  RSS feed

 
Raymund Nickel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
im working with JSF 1.2_12 and Facelets 1.11.14. Im trying to add a facelet programmatically.
Thatfore i need a FaceletFactory which i should get by calling FaceletFactory.getInstance().
It doesnt matter where or when(in a Servlet-Container or Unittest), it always returns null...
Anybody has some experience with that problem?

thanks a lot,
Ray
 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, but it's hard to get any JSF components in a unit test. The JSF context only exists when an actual JSF request is being processed and not in a simple JSP or servlet. It's likely that the same circumstances apply for the FaceletFactory.

A lot of people assume that JSF is a "control program" that runs all the time. It's not. JSF data structures are built by the FacesServlet to handle a single request, then discarded after the response has been sent. Next request, they get built all over again. In the mean time, they don't exist.
 
Raymund Nickel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thank you for your reply. I guess thats the reason...
Is there a way or best practise store the factory somewhere?
Or when is it psooible to get the FaceletFactory?

thank you,
Ray
 
Tim Holloway
Bartender
Posts: 18713
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raymund Nickel wrote:Hi,
thank you for your reply. I guess thats the reason...
Is there a way or best practise store the factory somewhere?
Or when is it psooible to get the FaceletFactory?

thank you,
Ray


No. The only time stuff like that exists is when it's usable. A "pure" FacesContext doesn't exist, and likely the same can be said about the FaceletFactory.

A bigger concern, however, is that a good unit test shouldn't require any of the UI subsystem components to begin with. The unit tests should be more about exercising business logic, and business logic should be discrete from presentation logic.

You can, of course "unit test" presentation as well, using tools such as Cactus or JMeter, but they make legitimate web requests, and thus should be routing through the normal FaceServlet and filter environments, which means that the appropriate data structures will have been constructed when they were needed.

Facelets is mostly about framing content, however, and unless you're creating entire page layouts on the fly, I wouldn't generally recommend using the FaceletFactory, but rather stick to static facelet component tags. I'm having trouble finding the JavaDocs on that stuff anyway.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!