Archive

Posts Tagged ‘JSF’

Eureka moment – “could not find Factory: javax.faces.context.FacesContextFactory” and embedded tomcat and grails

August 23, 2013 Leave a comment

Whoa – major breakthrough

I have been to build a grails project and get it to use JSF and have kept running into problems like this when building grails plugin projects and trying to publish to the embedded tomcat – which I have tried and failed for about a year to get to the bottom of without success

...
INFO: Initializing Spring root WebApplicationContext
Aug 23, 2013 11:53:20 AM javax.faces.FactoryFinder$FactoryManager copyInjectionProviderFromFacesContext
SEVERE: Unable to obtain InjectionProvider from init time FacesContext. Does this container implement the Mojarra Injection SPI?
Aug 23, 2013 11:53:20 AM javax.faces.FactoryFinder$FactoryManager getFactory
SEVERE: Application was not properly initialized at startup, could not find Factory: javax.faces.context.FacesContextFactory. Attempting to find backup.
Aug 23, 2013 11:53:20 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1135)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379)
at javax.faces.webapp.FacesServlet.init(FacesServlet.java:350)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)

Then I was having the problem again this morning – must fourth attempt at getting past this little hurdle when I ran into the following item hidden away beneath google

about half way down there is a tiny comment about programmatically adding ctx.addListener(com.sun.faces.config.ConfigureListener.class); and the fact that the web.xml cant be found.

what it suggests you do is to add the following ctx.addContextInitParameter(“com.sun.faces.forceLoadConfiguration”, “true”);

so I tried the equivalent of this for the embedded comcat example in my plugin by adding this context param to the generated web.xml in the doWithXML closure in the plugin file

    def doWithWebDescriptor = { xml ->
        // TODO Implement additions to web.xml (optional), this event occurs before
		
		def contextParams = xml.'context-param'[0]
		contextParams + {
			'context-param' {
				'param-name' ('javax.faces.DEFAULT_SUFFIX')
				'param-value' ('.xhtml')
			}
			'context-param' {
				'param-name' ('javax.faces.PROJECT_STAGE')
				'param-value' ('Development')
			}
			'context-param' {
				'param-name' ('javax.faces.STATE_SAVING_METHOD')
				'param-value' ('client')
			}
			'context-param' {
				'param-name' ('javax.faces.FACELETS_REFRESH_PERIOD')
				'param-value' ('1')

			}
			'context-param' {
				'param-name' ('com.sun.faces.injectionProvider')
				//'param-value' ('com.sun.faces.vendor.WebContainerInjectionProvider')
				'param-value' ('com.softwood.SpringInjectionProvider')

			}
			//use this for embedded tomcat when web.xml is defined programatically and its not in the project directly
			'context-param' {
				'param-name' ('com.sun.faces.forceLoadConfiguration')
				'param-value' ('true')
			}
			
		}

now when you run it the plugin starts and correctly loads the faces config context and your app works ! Holly cow batman

think i’m going to log this as a bug under the grails jira and see if someone cleverer than me can figure out the why’s – but heigh that now works in embedded tomcat – hoorah

Getting a basic primefaces jsf web project to work …

August 16, 2013 6 comments

I had some tricky moments getting the basic primefaces jsf project to work – it started out by not rendering my .xhtml p: tags.

I went back to basics, a couple of forum hits later, etc and have documented step by step how to get the example in the primefaces documentation to work.  This is on the way to getting primefaces to work with Grails 2.

so baby steps first – here we go – no grails just a basic dynamic web project using primefaces tags – i’ve linked to the following word document showing how to do this.

basic primefaces jsf project

I hope this will help others past the early frustration when first trying to get primefaces/jsf to work as you’d expect

Categories: JSF Tags: ,
%d bloggers like this: