I'm building a web App using JSF 2.0 and had a jaf-facelets.1.1.10 jar in my WEB-INF > lib folder, so now I'm trying to remove that so I can use the built int facelets 2.0 I was reading through this Question which balusC answered and I've done that, except teh part where it saysI need to replace FaceletViewHandler by ViewHandlerWrapper. for that I saw this question, but I don't have any faceletViewhandler classes in my project.
as of now, my webxml looks like this ( please check taht I didn't miss anything, or I'm referencing something I shouldn't:
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>miloWeb</display-name>
<welcome-file-list>
<welcome-file>faces/pages/index.xhtml</welcome-file>
</welcome-file-list>
<listener>
<listener-class>com.bravo.listeners.ServletListener</listener-class>
</listener>
<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>
<servlet-name>PdfServlet</servlet-name>
<servlet-class>com.bravo.servlets.PdfServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PdfServlet</servlet-name>
<url-pattern>/PdfServlet</url-pattern>
</servlet-mapping>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<description>
This is to Have separated faces.config files
</description>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
/pages/history/faces-config.xml,
/pages/contactInformation/faces-config.xml,
/pages/childHealthRecord/faces-config.xml,
/pages/dashboard/faces-config.xml,
/pages/insurance/faces-config.xml,
/pages/search/faces-config.xml,
/pages/labs/faces-config.xml,
/pages/patient/faces-config.xml,
/pages/physical/faces-config.xml,
/pages/notes/faces-config.xml,
/pages/scheduler/faces-config.xml,
/pages/settings/faces-config.xml,
/pages/orderEntry/faces-config.xml,
/pages/vitals/faces-config.xml
</param-value>
</context-param>
<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>
</web-app>
And as you can see, I have quite a few faces-configs I removed the
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
And now it looks like this ( I know some features I don't need like the navigation, but does it really hurt to keep it taht way?):
<?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_0.xsd"
version="2.0">
<managed-bean>
<managed-bean-name>vitalsBB</managed-bean-name>
<managed-bean-class>com.bravo.vitals.VitalsBB</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>vitals</from-outcome>
<to-view-id>/pages/vitals/vitals.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
</faces-config>
after doing some changes and leaving it like that, I run the project on tomcatv7 and get this error:
java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:452)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:140)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:349)
Does that look like an error I would get for having my files like this? because all I did was remove the jar-facelets.1.1.10.jar and now I'm getting this Error. But teh App works fine b4 I remove the facelets jar, so what is the relationship between these two jars??
I tried adding the jstl.jar but that doesn't work, it just shows me this:
The error suggest include jstl-1.2.jar available here in the same folder where your jsf jars are.
There is no need for facelets 2.0 jar, because JSF 2.0 adopted facelets as its default View Declaration Language (VDL), and now it is bundled inside jsf jars (for both MyFaces and Mojarra)
To solve this issue, I had to Add the jstl-impl.jar and jstl-api.jar and update to the latest jsf-impl.jar and jsf-api.jar. That fixed it.
Don't really know why it never complained about it when the facelets.1.10.jar was there.
Related
I have a Vaadin application which uses ru.xpoft.vaadin.SpringVaadinServlet as its single servlet. Now I am trying to change the servlet class to com.vaadin.spring.server.SpringVaadinServlet.
But I don't know how to specify the UI class for com.vaadin.spring.server.SpringVaadinServlet inside web.xml. I know it is possible to specify the servlet and UI class without a web.xml(Using #WebServlet and #VaadinServletConfiguration annotations). But still I require to configure the servlet using web.xml.
Please help.
You can spedify servlet and UI like this in the web.xml (from the Vaadin 7 Documentation):
<?xml version="1.0" encoding="UTF-8"?>
<web-app
id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>
com.vaadin.server.VaadinServlet
</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>com.ex.myprj.MyUI</param-value>
</init-param>
<!-- If not using the default widget set-->
<init-param>
<param-name>widgetset</param-name>
<param-value>com.ex.myprj.AppWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
See also the Vaadin docs about Deploying an Application.
To publish one java-web application in tomcat, I copy the project that named 'demo-mvc' to the tomcat's webapps folder.Then I visit "http://localhost:8080/demo-mvc/xx.jsp" in the chorme browser after starting tomcat but it prompts "The requested resource is not available".I tried editing the server.xml as follows
<Context docBase="D:\apache-tomcat-7.0.57\webapps\demo-mvc" path="/demo-mvc" reloadable="true" source="org.eclipse.jst.jee.server:website"/>
Finally it still does no effect.I am confused about where the problem is.
Try to clean your project from Project clean option and make sure you are mapping all your resources
In your web.xml the code should be like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.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>
</web-app>
I'm trying to build custom URL as prettyfaces tells that it do, but after setup it, it gives me this error:
Referenced file contains errors (http://ocpsoft.org/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd). For more information, right click on the message in the Problems View and select "Show Details..."
This is how my web.xml setup:
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>BRAINSET</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.xhtml</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>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
</web-app>
And my pretty-config.xml :
<pretty-config xmlns="http://ocpsoft.org/prettyfaces/3.3.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.org/prettyfaces/3.3.3
http://ocpsoft.org/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">
<url-mapping id="home">
<pattern value="/home" />
<view-id value="/index.xhtml" />
</url-mapping>
With this error I can't even deploy my app in Glassfish:
Could not publish to the server.
java.lang.NullPointerException
Any idea how to fix this ? Or should I look for another tool similar to prettyfaces ?
update
I don't think that this error is caused by PrettyFaces. The XML schema works fine in my Eclipse setup and I don't get any of these errors. And I'm pretty sure that the XSD file is valid.
You should have a look at the Eclipse log file (WORKSPACE/.metadata/.log) to have a look if there is any exception thrown.
BTW: You could also try to remove the schemaLocation element from your pretty-config.xml and check if this helps. PrettyFaces doesn't use the XSD schema when parsing the file. Something like this:
<pretty-config xmlns="http://ocpsoft.org/prettyfaces/3.3.3">
...
</pretty-config>
Finally figured this out.... so the reason this XSD isn't valid is because the document has this:
<?xml version="1.0" encoding="UTF-8" ?>
instead of:
<?xml version="1.0" encoding="UTF-8"?>
If anyone knows how to get ahold of Lincoln to fix this, that'd be great!
I have added the following content to my web.xml for a servlet context listener---
<listener>
<listener-class>
com.anyaservices.log4j.ApplicationServletContextListener
</listener-class>
</listener>
I have added this immediately after the end of "welcome-file-list"
The last line of the welcome-file-list node is given below--
</welcome-file-list>
Now, I have made some changes to a servlet so that it can use the context listener... in addition to the servlet there is a "Hello.jsp" file that just displays a welcome message.
I have not made any changes to the JSP file. However after my code changes for the servlet context listener, when I try to go to Hello.jsp I get an error in Tomcat= The requested resource is not available.
What have I done wrong here? Why is the JSP file not being shown now?
EDIT-- I have posted the entire content of my web.xml below--
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Test Web Application</display-name>
<welcome-file-list>
<welcome-file>index.html</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>Hello.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
com.test.log4j.ApplicationServletContextListener
</listener-class>
</listener>
<servlet>
<description>Used to run a single crawl job</description>
<display-name>runsinglecrawljob</display-name>
<servlet-name>runsinglecrawljob</servlet-name>
<servlet-class>com.test.runsinglecrawljob</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>runsinglecrawljob</servlet-name>
<url-pattern>/runsinglecrawljob</url-pattern>
</servlet-mapping>
<servlet>
<description>Home page</description>
<display-name>home</display-name>
<servlet-name>home</servlet-name>
<servlet-class>home</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>home</servlet-name>
<url-pattern>/home</url-pattern>
</servlet-mapping>
<servlet>
<description>Run a single crawl job after asking users for parameters of that job</description>
<display-name>runsinglejob</display-name>
<servlet-name>runsinglejob</servlet-name>
<servlet-class>com.test.runsinglecrawljob</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>runsinglejob</servlet-name>
<url-pattern>/runsinglejob</url-pattern>
</servlet-mapping>
</web-app>
The URL I am trying to access is http ://localhost:8080/test_web_app/Hello.jsp
Tomcat handles JSP files through org.apache.jasper.servlet.JspServlet. Perhaps somehow your listener class is interfering with the operation of the JspServlet. There is no need to list all of those files in your welcome file list. Any jsp file inside the war should be available (but it should not be placed inside the WEB-INF or META-INF folders.)
I think you should check your log4j configuration. Did you initialize log4j with a log4j.properties file in WEB-INF/classes?
Most tutorials propose a default JSF configuration similar to the following web.xml:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</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>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
With this configuration the corresponding *.xhtml files in my webapp are only found by the Faces Servlet if the corresponding URLs ends with the file extension .jsf (e.g. http://localhost/welcome.jsf). Is it possible to configure web.xml so URLs that do not end with .jsf are also processed as JSF pages using the same *.xhtml files?
In other words I would like to have URLs that do not depend on the server side implementation.
You can use Filter to hide this extension and make your URL SEO friendly. One such implementation of Filter is PrettyFaces.
For example:
If you need http://host:port/yourapp/login to resolve with your login.xhtml then in pretty filter configure following way
<url-mapping id="login">
<pattern> /login </pattern>
<view-id> /legacy/user/login.jsf </view-id>
</url-mapping>
Have a look at two min video tutorial
you can create url mapping like this
create faces-config.xml file in WEB-INF folder
<?xml version="1.0" encoding="ISO-8859-1"?>
<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_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>/jsf/demoapp</from-view-id>
<navigation-case>
<from-outcome>demoapp</from-outcome>
<to-view-id>/demoapp.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
in web.xml you have to do 2 entries
<servlet>
<servlet-name>jsfServlets</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jsfServlets</servlet-name>
<url-pattern>/jsf/*</url-pattern>
</servlet-mapping>