RichFaces GUI displayed as text - jsf

I am running a simple RichFaces example. Mainly using Tabs. The example is shown on
JBoss website found at:
http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=tabPanel&skin=blueSky
Running the code results in the following page:
Overview
«
↓
»
RichFaces is a component library for JSF and an advanced framework for easily integrating
AJAX capabilities into business applications.
100+ AJAX enabled components in two libraries
...
Notice the overview should be a clickable tab. Instead I get
Overview
«
↓
»
There is no error messages from the GlassFish server. I am using Netbeans with Facelets, RichFaces 4.0 and JSF 2.0.
My web.xml is
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/richexample.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Library:
richfaces-components-api-4.0.0.Final.jar
richfaces-components-ui-4.0.0.Final.jar
richfaces-core-api-4.0.0.Final.jar
richfaces-core-impl-4.0.0.Final.jar
sac-1.3.jar
guava-10.0.1.jar
cssparser-0.9.5.jar
GlassFish 3.x (libraries)
Appreciate any hint or feedback as I do not have a clue why graphics are not displayed.

What URL did you use to access your page? In your web.xml you mapped Faces Servlet to the /faces prefix, so your URL must include this (even though your actual page is not really on that path).
You can add additional mappings in your web.xml, like the common *.jsf or *.xhtml or replace the existing one, e.g.
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

Related

Tomcat8 start failure with Primefaces JSF App

I have a JSF2.2 application running fine on Tomcat7. I now have to move it to Tomcat8 and the application is not starting anymore.
The error is:
03-Jul-2019 15:41:47.655 INFO [localhost-startStop-1] org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 5.1
03-Jul-2019 15:41:47.655 INFO [localhost-startStop-1] org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 5.1
03-Jul-2019 15:41:47.655 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
03-Jul-2019 15:41:47.659 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/NPSAdmin] startup failed due to previous errors
03-Jul-2019 15:41:47.662 SEVERE [localhost-startStop-1] javax.faces.FactoryFinder$FactoryManager.getFactory Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory. Attempting to find backup.
03-Jul-2019 15:41:47.663 SEVERE [localhost-startStop-1] com.sun.faces.config.ConfigureListener.contextDestroyed Unexpected exception when attempting to tear down the Mojarra runtime
java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1135)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:379)
at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:140)
at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:310)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4817)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5474)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:226)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:980)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1851)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I have been searching for similar issues and could not solve it. In my tomcat lib I have the servlet-api.jar, but no other jsf related file.
In my webapp I have:
jsf-api-2.2.2.jar
jsf-impl-2.2.2.jar
primefaces-5.1.jar
No other jar like javax.faces have been found in the lib directories
We can also see from the logs that primefaces is found and activated:
org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 5.1
So my feeling is that it is not a classpatch issue explaining why the Factory was not found.
I searched the tomcat logs, but there is nothing in it
I am running this issue with Tomcat8 on mac osX and on ubuntu
My web.xml is like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>NPSAdmin</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/securityContext.xml
</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>npsadmin</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- JNDI DB Connection -->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/AnonymDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Thank you for your comments. I had also tried to remove com.sun.faces.config.ConfigureListener entry in web.xml.
This did not change.
The reason was simple: a spring component could not start because of a configuration issue. This is where the issue was. The error message was misleading.
I corrected the the configuration and it works.
Please be aware that this error message can be misleading

Facelets error page works during ajax request with FullAjaxExceptionHandler, but does not evaluate EL during synchronous request

I am trying to configure a normal (non-ajax) request error page using Omnifaces library. I am able to use the FullAjaxExceptionHandler and with ajax request error and its page as shown in the demo. When I use the same error page with normal request the error page is shown, but the values are displayed as source code (for example Date/time: #{of:formatDate(now, 'yyyy-MM-dd HH:mm:ss')} User agent: #{header['user-agent']} .. are displayed in the browser as it is).
I am using Tomcat 7, JSF 2.2 (MyFaces), Weld 2.6 (for CDI), Omnifaces 2.0 and Primefaces 5.1. The following is the relevant code.
The page:
<h:commandButton value="Throw runtime exception on normal request"
action="#{appbean.throwRuntimeException}"/>
<p:commandButton value="Throw runtime exception on AJAX request"
action="#{appbean.throwRuntimeException}"/>
The bean:
public void throwRuntimeException() {
throw new RuntimeException("peek-a-boo");
}
faces-config:
<factory>
<exception-handler-factory>
org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory
</exception-handler-factory>
</factory>
web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>facesExceptionFilter</filter-name>
<filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>facesExceptionFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/WEB-INF/errorpages/error2.xhtml</location>
</error-page>
The <error-page><location> must match the FacesServlet mapping in order to get FacesServlet to run on the error page too during an exception on a synchronous request (which doesn't use ViewHandler#renderView(), but RequestDispatcher#forward()).
Alter the mapping accordingly:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Using /faces/* (and *.faces) is soo JSF 1.0/1.1. If you really need to keep /faces/* for some reason (e.g. existing webapp with already published URLs), then just use both (and migrate with 301s accordingly):
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
See also:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output

Declaring custom PDF servlets collides with .xhtml extension

I'm trying to implement a custom PDF file servlet (/fileprovider/name?param1=value&param2=otherValue) on a JSF 2 web application, but when declaring it on web.xml the application always adds .xhtml extension to every request. I believe due to the DEFAULT_SUFFIX context-param.
<!-- ... -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/*.xhtml</param-value>
</context-param>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MyPDFServlet</servlet-name>
<servlet-class>com.company.servlet.MyPDFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyPDFServlet</servlet-name>
<url-pattern>/fileprovider/name</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- ... -->
The exception thrown is:
FacesFileNotFoundException: /name.xhtml Not Found in ExternalContext as a Resource
So I believe that the path is not mapped correctly, maybe I'm missing something.
Is there any way to specify that I want specific paths to point to custom servlets without adding .xhtml extension?

Direct two diferrent URL to the same page in JSF

I am developing a jsf2 + spring3 application with the following filesystem:
webapp
-resources (folder)
-WEB-INF (folder)
--applicationContext.xml
--faces-config.xml
--web.xml
-buy.xhtml
-company.xhtml
-home.xhtml
-sell.xhtml
And I got this in my web.xml:
<welcome-file-list>
<welcome-file>home.jsf</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
My faces-config.xml got nothing about navigation.
When I go to the following URL "http://:8080/website/" I got the "home.jsf" view.
I need to go to the same "home.jsf" view "http://:8080/website/home.jsf" when I write the following URL "http://:8080/website/caminha/"
How can I achieve this? What I need to change in web.xml or in faces-config.xml? Thanks!

Can't get CXF JAX-RS and JSF to work together

I'm trying to setup a small example application FooTest that uses CXF JAX-RS and JSF. I started with the CXF part, implemented a simple service (works) and a small html page called home.html (I can access it in my browser). The relevant code is as follows:
web.xml
<servlet>
<servlet-name>RestServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>jaxrs.serviceClasses</param-name>
<param-value>com.test.FooService</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
FooService.java
#Path("/rest")
public class FooService {
#Path("/foo")
#GET
#Produces("application/json; charset=UTF-8")
public String getFoo() {
// returns json
}
}
Now I can call http://localhost:8080/FooTest/rest/foo and http://localhost:8080/FooTest/home.html. However when I start defining and mapping the FacesServlet to *.html and try to access home.html I get a NullPointerException.
New web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
... CXF stuff ...
Leads to
Apr 25, 2013 6:08:17 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at org.apache.myfaces.shared.context.flash.FlashImpl.isKeepMessages(FlashImpl.java:388)
at org.apache.myfaces.shared.context.flash.FlashImpl._saveMessages(FlashImpl.java:665)
at org.apache.myfaces.shared.context.flash.FlashImpl.doPostPhaseActions(FlashImpl.java:269)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:254)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:369)
at org.apache.myfaces.view.jsp.JspViewDeclarationLanguage.buildView(JspViewDeclarationLanguage.java:99)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:78)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)
... infinite loop from FacesServlet:199 on ...
How can I fix this?
Update - More config info
The application runs on the JAX-RS version of TomEE 1.5.2.
src/main/webapp/WEB-INF/faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
</faces-config>
Update - Solution
(Thanks to David Blevins for clarification and pointing me to a useful example)
Remove the CXF configuration part, it is not required. Rename home.html to home.xhtml, since .xhtml is the javax.faces.DEFAULT_SUFFIX for JSF pages. Keep the FacesServlet mapping if you want to access your JSF pages using the .html extension. This is sufficient:
<?xml version="1.0" encoding="UTF-8"?>
<web-app ... >
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
Not sure whether this should be a comment or an answer, but you shouldn't setup CXFNonSpringJaxrsServlet and FacesServlet in your web.xml, all that stuff is there and ready to go. The goal with TomEE is you can skip the server-building and proceed directly to app-building.
CXF is fully integrated into Tomcat in TomEE to the point where even WS-Security works on Tomcat Realms. You just start using it by adding #ApplicationPath annotated components or EJBs annotated with #Path and they will be picked up and deployed automatically.
MyFaces is good to go and fully integrated with CDI so even things like #ConversationScoped work out of the box. You just need your faces-config.xml or some #ManagedBean classes.

Resources