• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FaceletFactory.getInstance() returns null

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic