im new to vaadin but noticed that you can in vaadin 6 set the default page in the web.xml file but in vaadin 7 this has been done away with.
how do i change the default page ?
Thanks
I am not quite sure what you mean by "default page", so I have to make some guesses.
As you say that you are missing the web.xml, you probably mean a project created by Vaadin Plugin for Eclipse or the Maven archetype. By default, the wizard (or Maven archetype) creates a project stub that uses Servlet API 3.0 deployment with #WebServlet annotation for the servlet class, which is a static class nested in the UI class. It can also be a regular (non-nested and non-static) class, but that's how it is in the application stub.
If you choose Servlet API 2.4 for the new Vaadin 7 Eclipse project, it will use web.xml to define the servlet and UI class, as well as their parameters.
You can mix #WebServlet and web.xml deployment, in which case settings done in web.xml override the ones given with #WebServlet annotation.
Default page to serve is not actually a need to be defined since the framwork handles everything, especially with 3.0 servlet implementation.
But sometimes one may need such file (like, for example, to add context listeners for Spring).
So you can either select the option to generate it during project creation or just make a blank web.xml file in WebContent/WEB-INF.
The autogenerated plugin file looks like:
<?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" id="WebApp_ID" version="3.0">
<display-name>YOUR_APP_NAME</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>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Related
I have some Facelets files like below.
WebContent
|-- index.xhtml
|-- register.xhtml
|-- templates
| |--userForm.xhtml
| `--banner.xhtml
:
Both pages are using templates from /templates directory. My /index.xhtml opens fine in browser. I get the generated HTML output. I have a link in /index.xhtml file to /register.xhtml file.
However, my /register.xhtml is not getting parsed and returns as plain XHTML / raw XML instead of its generated HTML output. All EL expressions in form of #{...} are displayed as-is instead of that their results are being printed. When I rightclick page in browser and do View page source, then I still see the original XHTML source code instead of the generated HTML output. For example, the <h:body> did not become a <body>. It looks like that the template is not being executed.
However, when I open the /register.xhtml like /faces/register.xhtml in browser's address bar, then it displays correctly. How is this caused and how can I solve it?
There are three main causes.
FacesServlet is not invoked.
XML namespace URIs are missing or wrong.
Multiple JSF implemenations have been loaded.
1. Make sure that URL matches FacesServlet mapping
The URL of the link (the URL as you see in browser's address bar) has to match the <url-pattern> of the FacesServlet as definied in web.xml in order to get all the JSF works to run. The FacesServlet is the one responsible for parsing the XHTML file, collecting submitted form values, performing conversion/validation, updating models, invoking actions and generating HTML output. If you don't invoke the FacesServlet by URL, then all you would get (and see via rightclick, View Source in browser) is indeed the raw XHTML source code.
If the <url-pattern> is for example *.jsf, then the link should point to /register.jsf and not /register.xhtml. If it's for example /faces/*, like you have, then the link should point to /faces/register.xhtml and not /register.xhtml. One way to avoid this confusion is to just change the <url-pattern> from /faces/* to *.xhtml. The below is thus the ideal mapping:
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
If you can't change the <url-pattern> to *.xhtml for some reason, then you probably would also like to prevent endusers from directly accessing XHTML source code files by URL. In that case you can add a <security-constraint> on the <url-pattern> of *.xhtml with an empty <auth-constraint> in web.xml which prevents that:
<security-constraint>
<display-name>Restrict direct access to XHTML files</display-name>
<web-resource-collection>
<web-resource-name>XHTML files</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
JSF 2.3 which was introduced April 2017 has already solved all of above by automatically registering the FacesServlet on an URL pattern of *.xhtml during webapp's startup. The alternative is thus to simply upgrade to latest available JSF version which should be JSF 2.3 or higher. But ideally you should still explicitly register the FacesServlet on only one URL pattern of *.xhtml because having multiple possible URLs for exactly the same resource like /register.xhtml, /register.jsf, /register.faces and /faces/register.xhtml is bad for SEO.
See also:
Set default home page via <welcome-file> in JSF project
Opening JSF Facelets page shows "This XML file does not appear to have any style information associated with it."
Sometimes I see JSF URL is *.jsf, sometimes *.xhtml and sometimes /faces/*. Why?
JavaServer Faces 2.2 and HTML5 support, why is XHTML still being used
Which XHTML files do I need to put in /WEB-INF and which not?
Our servlets wiki - to learn the mandatory basics about servlets
2. Make sure that XML namespaces match JSF version
Since introduction of JSF 2.2, another probable cause is that XML namespaces don't match the JSF version. The xmlns.jcp.org like below is new since JSF 2.2 and does not work in older JSF versions. The symptoms are almost the same as if the FacesServlet is not invoked.
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
If you can't upgrade to JSF 2.2 or higher, then you need to use the old java.sun.com XML namespaces instead:
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
But ideally you should always use the latest version where available.
See also:
Which XML namespace to use with JSF 2.2 and up
JSF tags not executed
Warning: This page calls for XML namespace http://xmlns.jcp.org/jsf/XXX declared with prefix XXX but no taglibrary exists for that namespace
3. Multiple JSF implementations have been loaded
One more probable cause is that multiple JSF implementations have been loaded by your webapp, conflicting and corrupting each other. For example, when your webapp's runtime classpath is polluted with multiple different versioned JSF libraries, or in the specific Mojarra 2.x + Tomcat 8.x combination, when there's an unnecessary ConfigureListener entry in webapp's web.xml causing it to be loaded twice.
<!-- You MUST remove this one from web.xml! -->
<!-- This is actually a workaround for buggy GlassFish3 and Jetty servers. -->
<!-- When leaving this in and you're targeting Tomcat, you'll run into trouble. -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
When using Maven, make absolutely sure that you declare the dependencies the right way and that you understand dependency scopes. Importantingly, do not bundle dependencies in webapp when those are already provided by the target server.
See also:
Configuration of com.sun.faces.config.ConfigureListener
How to properly install and configure JSF libraries via Maven?
Make sure that you learn JSF the right way
JSF has a very steep learning curve for those unfamiliar with basic HTTP, HTML and Servlets. There are a lot of low quality resources on the Internet. Please ignore code snippet scraping sites maintained by amateurs with primary focus on advertisement income instead of on teaching, such as roseindia, tutorialspoint, javabeat, baeldung, etc. They are easily recognizable by disturbing advertising links/banners. Also please ignore resources dealing with jurassic JSF 1.x. They are easily recognizable by using JSP files instead of XHTML files. JSP as view technology was deprecated since JSF 2.0 at 2009 already.
To get started the right way, start at our JSF wiki page and order an authoritative book.
See also:
Java / Jakarta EE web development, where do I start and what skills do I need?
What is the need of JSF, when UI can be achieved with JavaScript libraries such as jQuery and AngularJS
My first page to be called for the Struts application should be a simple helloWorld.jsp page. This is specified in the web.xml like this:
<welcome-file-list>
<welcome-file>helloWorld.jsp</welcome-file>
</welcome-file-list>
But Im getting an HTTP 404 error. What would be the correct struts.xml structure for this? Is one actually needed for the default page to be called? If not then why am I getting the error? Yes the jsp file is located in the WEB-INF folder
Thanks
EDIT
Added screenshot displaying location of JSP file:
This has nothing to do with Struts 2. This jsp should be hit as a JSP of the webapp, which doesn't go through Struts 2. Troubleshooting this amounts to verifying that your webapp was loaded by the servlet container and that you have the correcty URL to hit the webapp and then this JSP.
You should look in the servlet container logs to verify that the startup of the container went okay, and it should also report to you that your webapp was loaded, init'd and started.
Next, verify that your URL is correct. I would assume something like this:
http://localhost:8080/myWebAppContextName/helloWorld.jsp
The webapp context name could be different things depending upon how you deployed and configured your webapp. If you simply dropped the war file into a tomcat's webapps folder, it will be the name of the webapp.
**Make sure that your jsp should be there in `WebRoot` folder.**
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
index.jsp
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=welcome.action">
I trying to upgrade from OrbeonForms version 3.8 to 3.9. I'm using PriorityResourceManagerFactory as follows:
<context-param>
<param-name>oxf.resources.factory</param-name>
<param-value>org.orbeon.oxf.resources.PriorityResourceManagerFactory</param-value>
</context-param>
<!-- Uncomment this for the filesystem resource manager -->
<context-param>
<param-name>oxf.resources.priority.1</param-name>
<param-value>org.orbeon.oxf.resources.FilesystemResourceManagerFactory</param-value>
</context-param>
<context-param>
<param-name>oxf.resources.priority.1.oxf.resources.filesystem.sandbox-directory</param-name>
<param-value>d:/Sources/esb-repository/user-interface</param-value>
</context-param>
<context-param>
<param-name>oxf.resources.priority.2</param-name>
<param-value>org.orbeon.oxf.resources.WebAppResourceManagerFactory</param-value>
</context-param>
<context-param>
<param-name>oxf.resources.priority.2.oxf.resources.webapp.rootdir</param-name>
<param-value>/WEB-INF/resources</param-value>
</context-param>
<context-param>
<param-name>oxf.resources.priority.3</param-name>
<param-value>org.orbeon.oxf.resources.FilesystemResourceManagerFactory</param-value>
</context-param>
<context-param>
<param-name>oxf.resources.priority.3</param-name>
<param-value>org.orbeon.oxf.resources.ClassLoaderResourceManagerFactory</param-value>
</context-param>
I have entry in page-flow.xml:
<files path-info=".+\.(gif|css|pdf|json|js|png|jpg|xsd|ico)"
matcher="oxf:perl5-matcher"/>
Within my directory I keep whole application code and I have file theme/styles/layout.css. In Orbeon 3.8 server path /orbeon/theme/styles/layout.css works perfectly, but not in 3.9.
How to configure it to keep backward compatibility?
I'll assume /orbeon is the context on which you deployed the Orbeon Forms web app.
If you're using Orbeon Forms PE, starting with 3.9 versioned resources are enabled by default, the path requested by the browser needs to be /orbeon/3.14/theme/styles/layout.css, where 3.14 is the app version. If you write /theme/styles/layout.css in your code, Orbeon Forms will automatically rewrite it for you, adding the version number in the HTML it sends to the browser.
Since 3.9, the default app path is prepended when looking up resources. So a request for /orbeon/3.14/theme/styles/layout.css, with versioned resources, or /orbeon/theme/styles/layout.css without versioned resources, will look for the file app/theme/styles/layout.css in your resource directory. So you need to either:
Move your CSS to a different place on disk (move theme under the app directory).
Add theme as a platform path, by adding it to the oxf.url-rewriting.platform-paths property. Most likely this is the option that makes the most sense for you.
I'm trying to do a simple forwarding to an error page in a JSF 2 application. The instructions everywhere seem simple enough but it just doesn't work for me. This is what I tried. I put the following in web.xml:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/pages/error.jsf</location>
</error-page>
I tried an exception-type java.lang.Exception, and I tried using error-code instead of the exception-type. I also tried to name the page (in the above snippet) error.xhtml, and I tried all this with an error.jsp page. Nothing works.
I'm testing this by simply disconnecting the database server so any attempt to log in causes an exception. And it's being displayed on the screen instead of the error page.
I'm using eclipse, tomcat 7, and myfaces 2.1.4. Also in my WEB-INF/lib I have primefaces-3.0.RC2 and prettyfaces-jsf2-3.3.2.
What am I doing wrong / not doing?
Have you shut down the error mechanisms of Facelets? In you web.xml file, you may need to have the following context-param:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
If you also use MyFaces, you need this additional context-param:
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>false</param-value>
</context-param>
This article may be useful to you.
Did you use any managed bean to process the error? If so, have you declared them? Check out this article.
How will i write My custom lifecycle listner for jsf 2
For jsf 1.2 BalusC has provided good tutorial but in JSF2 we do not have faces-config.xml
can we use faces-config.xml.if yes can you please provide me sample..If no then how do we register listners in jsf 2.0
Thanks A Lot
You can still create the file faces-config.xml and put in WEB-INF folder. The header of your faces-config.xml should look like this:
<?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">
// Your configuration here
</faces-config>
Notice that the version is now 2.0.