JSF 2.2 components are not rendered using Primefaces running on Spring and Maven [duplicate] - jsf-2.2

This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 6 years ago.
When I go to http://localhost:8081/installer/index.xhtml via IE11 or Firefox45, I see only Setup Wizard and no JSF components. The HTTP status code is 200. I do not have any errors on Tomcat 7.
It is running without problem on JSF 1.2. I am only not sure about web.xml file.
Thanks in advance. Can you advise me what can be wrong, please?
EDITED
When I changed extension from .xhtml to .faces, I got an useful exception on Tomcat output, thanks.

Please check the servlet mapping in 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>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Now which url you are running like here servlet is called when i will run http://localhost:Port/Path/PageName.jsf but when i will try to run http://localhost:Port/Path/PageName.xhtml it will not work. Or I have to us like this http://localhost:Port/faces/Path/PageName.xhtml
What is the difference between creating .xhtml or .jsp .or .jsf for JSF pages
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?

Related

CSS and HTML files not loading in IDE

My Java EE app is returning a 404 status when trying to load CSS and HTML files. Any ideas? Problem is happening with any browser, internal or external. The problem did not exist prior to editing a couple of JS files. In the process of troubleshooting JS files executions, I deleted and re-added my server and the problem has persisted ever since. All JS files are loading. The problem persists with deployment to the live website.
Add this to your web.xml
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>

Servlet mapping refers to a servlet that is not defined

I'm building a web project and have the following code in my web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
<enabled>true</enabled>
<async-supported>false</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
In eclipse markers window I see following error twice: The servlet mapping "Faces Servlet" refers to a servlet that is not defined. Well, in my opinion it is defined right there. When I delete servlet-mapping nodes, error disappears, but the project is useless. I've tried to re-validate project and web.xml file, refresh dependencies from maven. I haven't succeeded in finding anything relevant in google search. Also, I used very similar web.xml file in another project(not maven) and there it worked fine.
How can I fix this error?

welcome-file does not work in WebLogic

When I deploy my web application (Spring MVC) on WebLogic, the welcome page does not launch with the default URL http://my.site.com/myApp. I have my welcome page under home directory and I set as follows in web.xml.
<welcome-file-list>
<welcome-file>/home/index.html</welcome-file>
</welcome-file-list>
I am able to access the page using the full URL http://my.site.com/myApp/home/index.html.
Also, if I put index.html directly under the root and update web.xml as follows, the welcome page launches with the default URL
<welcome-file>/index.html</welcome-file>
What should I do to make the default URL launch the index.html under home directory ?
Here is the code in web.xml and applicationContext.xml.
web.xml:
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
applicationContext.xml:
<mvc:default-servlet-handler/>
I assume it has something to do with the leading slash. Have you tried simply home/index.html instead of /home/index.html.
This user asked the same question but had it work without the initial slash: can-i-set-tomcat-with-a-welcome-file-in-a-subfolder
Another discussion on the same topic:
I also had the same issue.
Make sure that the file you are trying to show is outside the
web-inf folder.
There are some configurations available in weblogic.xml file but none seems to work.I think it's a security feature or something else not sure exactly what.
In my case dispatcher servlet was capturing the empty request and showing no mapping found. May be you can create a controller mapping for the same and be done with it.
The funny thing is the same thing was working flawlessly in tomcat 7

java.lang.IllegalStateException: Cannot forward after response has been committed while including HTML files using jsp:include

When <jsp:include> is used for including HTML file DispatcherServlet is throwing
java.lang.IllegalStateException: Cannot forward after response has been committed
I have one servlet:
<servlet-mapping>
<servlet-name>web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
In it, I have enabled Spring MVC annotations and have handler mapping and adapter for JSP files without controllers (converting old webapp to Spring). And I have enabled DefaultServletHttpRequestHandler in this Servlet.
Any idea how to avoid that IllegalStateException when including html files?
So if you let spring handle all html files, it will always fail on jsp:include because spring cannot handle html includes.
Best way around this for me was to leave html files on default servlet.
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
and leave rest on DispatcherServlet.
<servlet>
<servlet-name>web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
This is definitely not a best solution, but until I convert all jsps (around 1000 of them) to mvc and something like tiles this is the only way I can see it working.
It is illegal to call forward() after some response is written to the output stream. The response may have been already sent to the client.
This article Causes of Response already committed explains why response is already committed.
I tried the proposed solution which declares the default servlet mapping for *.html url patterns and it worked fine. The only problem was that it introduced some side effects in my case (an hybrid webapp, spring and non-spring managed): html files that should have been managed by Spring's front controller now were managed by Tomcat's default controller.Fortunately, I found a couple of solutions with zero impact on the rest of the webapp.
Use .jsp file extension instead of .html. Spring won't complain if
it finds <jsp:include page="file.jsp" /> instead of <jsp:include page="file.html" />
Include the .html file in a scriptlet <%=file.html %> and avoid using the jsp "include" tag

Spring MVC: favicon

I am using Spring MVC with such definition:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
But the problem that spring always trying to find /favicon.ico by default and as a result I can't render any page. How can I disable such behaviour?
Thank you
If you are using Spring Security, then make sure you have omitted the favicon request (and any other static resources) from the security filter chain.
It has nothing to do with spring mvc but that is the default behaviour of the browser you are using. Also that should not break anything at all and your app should work as normal even if it does not have an ico. (Unless you specifically coded to make it fail in case of missing ico)

Resources