Jsf Servlet Does not work IntelliJ Idea - jsf

I am currently trying to learn java ee basics and there is a simple jsf example project to get learn intelliJ idea as well. Before IntelliJ I was able to develop jsf project with maven in Eclipse and they were working good but when i did the exact same things in the same order (project from webapp archetype, add dependencies to pom, run maven, add jsf servlet to web xml and deploy) I got 404 error in return. Don't know if it arrises from some config must be done in intellij or something independent from intellij.
So here is my code and when i type localhost:8080/faces/index.xhtml either the faces servlet does not get triggered or something else happens so that the xhtml page is not found
1-project structure:
2-web.xml:
<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>
Most probably these two can explain the issue. Thanks for any help :)

I saw this post late, but I hope it helps someone else.
Under Project Structure makes sure you configured JSF:

You almost certainly failed to add a web facet and artifact to your project. See the IntelliJ documentation.

Related

java.lang.IllegalStateException:Could not find backup for factory javax.faces.application.ApplicationFactory

I'm using this :
Tomcat 7.0
JSF 2.0
JRE 7
but when trying to run my application, I got the following exception:
java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1011)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getApplication(FacesContextImplBase.java:159)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getELContext(FacesContextImplBase.java:210)
at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:1463)
at org.apache.myfaces.webapp.AbstractFacesInitializer._createFacesContext(AbstractFacesInitializer.java:477)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initStartupFacesContext(AbstractFacesInitializer.java:449)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:113)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any ideas why?
Thanks,
That may happen if your webapp's runtime classpath is polluted with multiple JSF impls/versions. The org.apache.myfaces entries in the stack trace tells that you're using MyFaces. This problem thus suggests that you've another JSF implementation like Mojarra in the webapp's runtime classpath which is conflicting with it. It's recognizable by jsf-api.jar, or jsf-impl.jar, or javax.faces.jar. If you remove all of them, then this problem should disappear.
Or, if you actually intented to use Mojarra instead of MyFaces (you did namely not explicitly state the intented JSF impl/version anywhere in your question, but you just generically stated the JSF spec as in "JSF 2.0", so perhaps you actually had no clue what you was all doing), then you should be removing myfaces-*.jar files from your webapp.
See also:
JSF wiki page - Installing JSF
How to properly install and configure JSF libraries via Maven?
Difference between Mojarra and MyFaces
JSF implementations and component libraries
Complementing BalusC's answer, I recently got this error when trying to run an independent JAR with a Spring Boot application that has JSF as front-end with Spring-managed beans. Switching the packaging from JAR to WAR solved the problem.
For me {Tomcat 8, JSF 2.2, JRE 8}, the following steps worked:
Download JSTL jars API && IMPL and place it in your Tomcat lib.
Since downloading Majorra directly from eclipse in project
facets configuration is recently impossible ; "Zip File is empty Exception",
manually download jsf-api.jar and jsf-impl.jar and include them in a
new user library added to build path(only once!).
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>TestJSF</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
<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>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
In addition to what's already said, I faced this issue when importing a third party project, the reason was that two profiles were defined in the pom.xml, one for My Faces and another for Mojarra.
If this is your case, you just need to select one of them with maven -P or in Project properties, Maven section, indicating the profile(s) to be used.
In my case this exception was caused on webapp shutdown by the presence of com.sun.faces.config.ConfigureListener in web.xml, running Mojarra 2.2.x under Tomcat 8.0. As described in this answer, this causes Tomcat to register that listener twice (both automatically and by virtue of the web.xml entry) and hence, among other things, its contextDestroyed method is executed twice, the second time producing the described exception (most probably because JSF was already shut down by the first listener registration).
I had no classpath conflict in my case: just one version of Mojarra (2.2.6) and no MyFaces.

How To Execute Solr Commit Before Closing The Web App?

Everyone. I Face A Problem In Solr Using, In Development Environment, Project Always Close And Start, Start And Close, When We Stop Tomcat, Some Solr Documents Are Remained Not Committed. How To Overcome This Headache, Can Anyone Show Some Ideas? Great Thanx.....
You can use a shutdown hook within your webapplication to handle the shutdowns and commit the data.
Use a class that implements ServletContextListener in your web.xml:
<web-app>
<!-- Usual stuff here -->
<listener>
<listener-class>solr.commitListerner</listener-class>
</listener>
</web-app>

Disabling OpenSSO default Web Services

How can i disable OpenSSO Web Services which are provided by default?
Currently my application's OpenSSO can be accessed by the following URL's:
http://host_machine.domain:8080/opensso/identityservices/IdentityServices
http://host_machine.domain:8080/opensso/identityservices?WSDL
This can only be done by tweaking web.xml
Have you tried to remove the following servlet-mappings?
IdentityServices
/identityservices/
IdentityServicesHandler
/identity/
Sidenote: If you're using newer agents they might not work anymore.
-Bernhard
Commented only this part in web.xml and it worked!!!
<servlet-mapping>
<servlet-name>IdentityServices</servlet-name>
<url-pattern>/identityservices/*</url-pattern>
</servlet-mapping>

Liferay 6.1 portlet: cannot get JSONWebService scans to happen when I deploy

Does anyone know the steps so that OUR OWN portlets' service builder entities and methods show up when hitting localhost:8080/my-portlet/jsonws? All my entities are remote-service annotated. #JSONWebService is on all my classes. I've added a chunk of XML to web.xml (per http://www.liferay.com/community/wiki/-/wiki/Main/JSON+Web+Services - a very fine wiki otherwise). But I don't see anything happening.
I can browse to http://localhost:8080/api/jsonws and see the portal's JSON methods.
Have I missed a setting? Is there some additional configuration needed?
Thanks.
It must be some miss-configuration:) Let me repeat the steps here.
After installing Liferay 6.1 CE GA1 try if JSONWS api is visible, by accessing following urls: http://localhost:8080/api/jsonws and (for example): http://localhost:8080/knowledge-base-portlet/api/jsonws
Now, create your portlet using latest Liferay SDK. Create at least one service method in *ServiceImpl. Run service builder
Add the following code in portlets web.xml:
<servlet>
<servlet-name>JSON Web Service Servlet</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalClassLoaderServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.liferay.portal.jsonwebservice.JSONWebServiceServlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSON Web Service Servlet</servlet-name>
<url-pattern>/api/jsonws/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSON Web Service Servlet</servlet-name>
<url-pattern>/api/secure/jsonws/*</url-pattern>
</servlet-mapping>
Build war and finally deploy portlet to Liferay. After few moments, portlet will be deployed and available. JSONWS will scan your classes and find all service methods. To test if everything went ok, visit: http://localhost:8080/*portlet-context*/api/jsonws
That's all:)

Using richfaces 3.3.3 with portlets(JSF 1.2 ) on IBM Websphere Portal 6.1 server

I am trying to use richfaces 3.3.3 multiple fileupload functionality. I was successfull using it in JSF1.2 with apache tomcat server, but not able to implement it in portlets( in IBM WebSphere portal 6.1 server).
I have the following jars added apart from the regular jsf jars in lib:=
commons-beanutils-1.7.0.jar, commons-collections-3.2.jar, commons-digester-1.8.jar, commons-logging-1.0.4.jar, jhighlight-1.0.jar, richfaces-api-3.3.3.Final.jar, richfaces-impl-3.3.3.Final.jar, richfaces-impl-jsf2-3.3.3.Final.jar, richfaces-ui-3.3.3.Final.jar.
Following were added(extra) in web.xml:-
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Defining and mapping the RichFaces filter -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
<init-param>
<param-name>createTempFiles</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
Rest all were as usual . With this i was able to use it without any problem on Tomcat.
But these configuration fails when I try to implement it in portlets.
Googling and reading other blogs suggested that there is problem with the portletbridge and I should be using jboss-portletbridge.Tried various combinations as suggested by many. getting different errors each time.
Can anyone help me on this. Any insight is appreciated...
JSF 1.2 is available on Portal 6.1 only if you installed Portal on WebSphere Application Server 7.x. That is highly unrecommendable, because using that configuration your environment does not have any vendor supported upgrade path. Migrations from 6.1+7.x combination are not supported by IBM. You'd better off changing the framework you are using to something that will not cause such problems for you.

Resources