NetBeans - Web application - Web pages subfolder - jsf

I created an Enterprise application, with an EJB and a war module. I added some XHTML files in the Web Pages folders organized like this:
Web Pages
WEB-INF
web.xml
protected
testNavigation2.xhtml
testNavigation.xhtml
I also configured the Faces Servlet with the url-pattern *.xhtml.
Having deployed my application I can access without problems the URL: host/projectname/testNavigation.xhtml. The testNavigation.xhtml file is shown.
But I can't access: host/projectname/protected/testNavigation2.xhtml. Using that URL results in:
HTTP Status 404 - /protected/testNavigation2.xhtml Not Found in
ExternalContext as a Resource
The server console (I'm using Glassfish 4.1) reports:
Warning: Context path from ServletContext: /meteocal-project-war
differs from path from bundle: meteocal-project-war Warning:
JSF1064: unable to find or serve resource,
/protected/testNavigation2.xhtml.
How can I make xhtml files accessible from subfolders? I did actually a lot of research on this and judging from what I've read the behaviour I'm experimenting seems weird.
I don't think this is needed, but I'll post the content of web.xml in case I'm wrong:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>protected/testNavigation2.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Thanks for your attention,
I'll greatly appreciate any help you can give

This answer has been posted by Tiny in a comment. I report that here to mark it as an answer.
You might have forgotten to deploy the application after you created the folder named protected having that XHTML file - testNavigation2.xhtml under the application root. Redeploy the application all over again from scratch.
NetBeans basically requires a hard deploy whenever you create folders in your application. If it were to happen even after you made a hard deploy, scan the file system on your operating system to see, if there is a folder named protected having the said XHTML file in the deployed WAR file. The symptom basically is only that the newly created folder protected itself along with the mentioned XHTML file is unavailable in the deployed WAR file.
by Tiny

Related

Is it possible to prevent redirecting / to /welcome-file when using OmniFaces ExtensionlessURLs

I'm using JSF 2.2 and OmniFaces ExtensionlessURLs to remove the file extensions from my URLs:
www.exmaple.com/appname/login.xhtml -> .../appname/login.
Now when I navigate to www.example.com/appname/ I always get forwarded to www.exmaple.com/appname/login. Is it possible to prevent this redirect and to instead serve login.xhtml from www.example.com/appname/?
My .xhtml-files are stored in /WebContent/html/.
Relevant details from my web.xml:
<welcome-file-list>
<welcome-file>login.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>
<enabled>true</enabled>
<async-supported>false</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/html/*.xhtml</param-value>
</context-param>
From the showcase:
Advanced configuration
See package documentation for configuration settings as to mapping, filtering and forwarding behavior.
From the package documentation:
Welcome files
If a <welcome-file> is defined in web.xml that's scanned by FacesViews AND REDIRECT_TO_EXTENSIONLESS is used (which is the default, see below), it's necessary to define an extensionless welcome file to prevent a request to / being redirected to /[welcome file]. E.g. without this http://example.com will redirect to say http://example.com/index.
For example:
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
In other words, edit your welcome file to say login instead of login.xhtml.
Unrelated to the concrete problem: note though that you seem to have a general misunderstanding of the exact meaning of a "welcome file", because it's a bit strange that you could possibly have a login.xhtml file in every single folder. See also Set default home page via <welcome-file> in JSF project

Receiving "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."

I have read this SO question, which suggests to add index.html, and I've done that, in addition to adding it in my <welcome-file-list>. The error still persists.
I am running TomEE 8.0.0-M1 with Java EE8 (and thus JSF 2.3), Java 11, and am running this through Intellij.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Project Structure
Web Facet
Error
Type: Status Report
Message: Not found
Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
URLs I have tried
http://localhost:8080
http://localhost:8080/MeetPatient
http://localhost:8080/MeetPatient/web
What should I do in order to for index.xhtml to be found?

Richfaces 4.3.3 ResourceOptimisation not compressing or packing js and css files

I am trying to enable compression and packaging of my css and js files in Richfaces 4.3.3 using the inbuilt optimisation features, but nothing I try seems to have any effect and all script and CSS files are still being loaded as separate entities - I've enabled the optimisation feature in my web.xml as follows
<context-param>
<param-name>org.richfaces.resourceOptimization.enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.resourceMapping.packedStages</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.resourceOptimization.compressionStages</param-name>
<param-value>Production</param-value>
</context-param>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.richfaces.webapp.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/org.richfaces.resources/*</url-pattern>
</servlet-mapping>
the links on my pages are being included like so
<h:outputStylesheet name="bootstrap.css" library="css" />
or
<h:outputScript library="js" name="bootstrap-dropdown.js" />
and these files are in the WEB-INF/resources folder. I may be mistaken, but I would then expect that richfaces would detect these files and add them into the packed.css and packed.js files, but these files are still being loaded separately. One final thing to note is that I have my PROJECT_STAGE set as follows in my faces-config.xml file
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
Any pointers or tips anyone could give me would be greatly appreciated!
You misunderstand how it works.
org.richfaces.resourceOptimization.enabled=true
means "when you're looking for resources, load the optimized ones." It doesn't create the packed.js/packed.css, those were created when the richfaces*.jar was built.
If you want your own resources being processed take a look at the richfaces maven plugin.

JSF page as welcome-file is not found by Tomcat and ends up in 404

Well, when i try to access my page in this way:
http://XXX.XXX.XXX.XX:8080/Odontonew
I got the error:
type Status report
message /Odontonew/
description The requested resource (/Odontonew/) is not available.
But if i try to acces in this way:
http://XXX.XXX.XXX.XX:8080/Odontonew/index.jon
This works fine. So i have sure my problem is in web.xml but i don't know where, see bellow my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<display-name>Odontonew</display-name>
<!-- Configuracao do Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</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>
<!-- Configuracao DO JSF -->
<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>*.jon</url-pattern>
</servlet-mapping>
<!-- Servlet para Direcionar imagens -->
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>br.com.odontonew.util.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/pictures/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jon</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>afterwork</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.writeStateAtFormEnd</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>pictureDirectory</param-name>
<param-value>${user.home}/webapp/Odontonew/pictures/</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>${user.home}/webapp/Odontonew/tmp/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
In root folder of my project i have the page "index.xhtml", but i wanna access the project with the path: http://XXX.XXX.XXX.XX:8080/Odontonew (without the index.jon or index.html).
It's caused because your <welcome-file>index.jon</welcome-file> does not physically exist in the root folder. There's only an index.xhtml. When a folder is being requested in the URL like /, then the servletcontainer will first check if the physical file as specified in <welcome-file> is present, so that it can decide whether to continue the request or return a 404. The servletcontainer does at that point not take the mappings of any registered servlets into account. In your particular case, index.jon is a virtual URL and does not represent a physically existing file, hence the 404.
You can solve this by placing an empty but physically existing index.jon file next to index.xhtml file in the same folder. This way you fool the servletcontainer that the index.jon really exists and then it will continue the request which will ultimately hit the FacesServlet who serves the index.xhtml.
An alternative is to change the FacesServlet URL pattern of *.jon to *.xhtml so that you never need to fiddle with virtual URLs. If you really need it to be *.jon for some unclear reason, then again another alternative is to rename the physical file from index.xhtml to index.jon and set javax.faces.DEFAULT_SUFFIX context parameter to .jon.
Note that the concrete problem is essentially unrelated to JSF. It's related to basic servlets. You'd have exactly the same problem when using a different kind of servlet.
See also:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
As stated in many answers on the topic, welcome file entry represents a physical file path relative to the current URL path ending with /. As you most plausibly don't have any index.jon file in your root directory, you get the error.
So, you can either create a physical file index.jon in you root folder (don't worry, the one rendered will be index.xhtml), or simply switch to *.xhtml URL pattern to get rid of this unnecessary stuff altogether.

web.xml changes to enable development mode in Groovlet

I am using the Cruise Control jetty container to deploy a Groovlet application. It appears that if I change the groovy files in the webapp directory that Jetty does not recompile the source and the changes aren't reflected in the webapp. How can I modify my web.xml file to check for updates on every load? I'm just using a simple web.xml:
<web-app>
<servlet>
<servlet-name>GroovyServlet</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GroovyServlet</servlet-name>
<url-pattern>*.groovy</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>myApp.groovy</welcome-file>
</welcome-file-list>
</web-app>
GroovyScriptEngine checks the last-modification date of the source file. If it is newer than the last cache entry, a recompile will certainly done.

Resources