JSF Form is not showing up [duplicate] - jsf

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 7 years ago.
My server is glassfish v3, my browser is firefox 3.6.3 and i am using Netbeans 6.8
My question is why the textfield is not showing up in my browser. I only see the label.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Lookup</title>
</h:head>
<h:body>
<fieldset>
<legend>Enter Your Customer ID</legend>
<p>Legal ids are id001, id002, and id003.</p>
<f:view>
<h:form>
Customer ID:
<h:inputText value="#{bankForm.customerId}" />
<h:commandButton value="Show Current Balance"
action="#{bankForm.findBalance}" />
</h:form>
</f:view>
</fieldset>
</h:body>
</html>
The web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.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>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>pages/customer-lookup</welcome-file>
</welcome-file-list>
</web-app>

You need to make sure that the request URL (as you enter in browser address bar) matches the url-pattern of the FacesServlet. I.e. do not open the page by http://example.com/context/page.xhtml, but open it by http://example.com/context/page.jsf. Otherwise the FacesServlet will not be invoked and your XHTML page with JSF components will not be parsed in any way. You'll only see "plain HTML" tags like <fieldset> and so on in the browser and you will see the JSF source code unchanged in the returned HTML source when you do a View Source in browser.

Add this to your web.xml :
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

The problem you faced with may be solved in web.xml file stored in the WEB-INF dir in your web application project. You need to open that file and add the following xml content in order to make your pages running properly.
<web-app>
...
...
...
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
If your .xml file doesnt exist in the mentioned dir, you can add it by clicking on your web application project, add new file and then choose Standard Deployment Descriptor (web.xml)

Check if you have configured Faces-Servlet on this page

Related

Why does my BootsFaces not render anything?

I am fairly new to Coding with Frameworks. I want to build a Website using JSF and found BootsFaces as a Framework. So I downloaded BootsFaces and followed https://www.bootsfaces.net/quick-start.jsf to get everything going. I added the .jar into the Java Build Path and started a Project like the quick-start. So far so good. Then I wanted to implement some more "advanced" stuff. So I tried to add https://showcase.bootsfaces.net/forms/buttonGroups.jsf just to test if everything works. It didn't, If I copy
<b:buttonGroup>
<b:button value="Left" />
<b:button value="Middle" />
<b:button value="Right" />
</b:buttonGroup>
My Site doesnt show anything when it loads.
Here is my index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:b="http://bootsfaces.net/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Basic Page</title>
</h:head>
<h:body>
<b:buttonGroup>
<b:button value="Left" />
<b:button value="Middle" />
<b:button value="Right" />
</b:buttonGroup>
</h:body>
</html>
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>Mew</display-name>
<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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>BootsFaces_USETHEME</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
I use Glassfish as a Server if thats important.
Did I forget/not see something very basic? Or isn't BootsFaces even supposed to work like this?

Primefaces resources are not loaded

I'm using Primefaces 5.3 with TomEE, but I when I access my pages the PF resources are not being loaded and I get the following error:
$ is not defined
PrimeFaces is not defined
Even when I access the resource URL I get the following error
URL:
http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo
Error:
XML Parsing Error: no root element found Location: http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo Line Number 1, Column 1
My page :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<f:view>
<p:growl id="notificationMessage" showDetail="true" />
<p:panel id="basic" header="Basic" footer="Movie Details" style="margin-bottom:20px">
<h:panelGrid columns="1" cellpadding="10">
<p:outputLabel for="mbbData" value="Data Value: " />
<p:inputText id="mbbData" value="#{mbbDataInputController.mbbData}" required="true" />
<p:commandButton action="#{mbbDataInputController.addMbb}" />
</h:panelGrid>
</p:panel>
</f:view>
</html>
web.xml:
<?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>my-service</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
WEB-INF/faces-config.xml
</param-value>
</context-param>
<!-- Faces Servlet -->
<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>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>rest-servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.huawei.myapp.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
I also tried to add the following to the page head:
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
but it did not work.
Also please note that as I debugged the PrimeResourceHandler class, the resource are being created and the resource path is in the right jar.
OK, I found the problem and the solution as follows.
Problem:
The problem is that I am using two servlets, javax.faces.webapp.FacesServlet for JSF and org.glassfish.jersey.servlet.ServletContainer for REST web services. and when I requested reource file, actually Jersey servlet were going to serve it for me not the faces servlet.
Solution:
I changed the web.xml url mapping as:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/javax.faces.resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>rest-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

RichFaces tags are not executed

I have created a Dynamic Web Project in Eclipse Luna , using JSF 2.2, Jboss AS 7. The problem is that no button is rendered in browser from this code <a4j:commandButton value="a4j button"></a4j:commandButton> after I run the project. The same is true for a4j:commandLink for example.
I tried to modify <url-pattern>/faces/*</url-pattern> into <url-pattern>*.xhtml</url-pattern> (found something like this on the internet) but no result.
Hitting Ctrl Space on <a4j: pops a list of tags so i guess richfaces is properly installed.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<h:form>
<rich:panel>
<a4j:commandButton value="a4j button"></a4j:commandButton>
</rich:panel>
</h:form>
</h:body>
</html>
web.xml file:
<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>TestProject</display-name>
<welcome-file-list>
<welcome-file>faces/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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
faces-config.xml file:
<faces-config
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-facesconfig_2_2.xsd"
version="2.2">
</faces-config>

Nothing works When i add JSF related tags in web.xml

When i add JSF related tags to web.xml nothing is working and it gives an error. If I remove XML tags in web.xml then all .jsp and servlets are working fine. I also added jsf-api.jar,jsf-impl.jar,jstl.jar and standard.jar to lib folder of my project still it is not working so i added these jar files to lib folder in tomcat too but still it is not working.
Error1 with index.xhtml to url:
XML Parsing Error: no element found
Location: http://www.touchegolfmart.com/index.xhtml
Line Number 1, Column 1:
Erro2 with out index.xhtml to url
File not found
Firefox can't find the file at http://www.touchegolfmart.com/.
my web.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.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>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Context path in server.xml in conf folder of tomcat is:
<Host name="touchegolfmart.com" appBase="/home/rathan">
<Alias>www.touchegolfmart.com</Alias>
<Context path="" reloadable="true" docBase="public_html" debug="1"/>
<!-- <Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>-->
</Host>
Folder structure is:
index.jsp
WEB-INF/classes
WEB-INF/lib
WEB-INF/faces-config.xml
WEB-INF/web.xml
WEB-lib/lib/jsf-api.jar,jsf-impl.jar,jstl.jar,standard.jar.
META-INF/context.xml
I quickly put some example.
Created T folder in webapp folder.
Created file hello.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
<h3>JSF 2.0 Hello World Example</h3>
<h:form>
<h:commandButton value="Click" action="welcome"></h:commandButton>
</h:form>
</h:body>
</html>
Created file welcome.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body bgcolor="white">
<h2>JSF 2.0 Hello World Example</h2>
</h:body>
</html>
After this created folder WEB-INF in T folder and created 2 files:
web.xml
<?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>JSFHelloWorld</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>faces/hello.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>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
faces-config.xml
<?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">
</faces-config>
also in T/WEB-INF folder created folder lib, which has jsf-api-2.1.12.jar, jsf-impl-2.1.12.jar, jstl-1.2.jar files.
This works, but I don't used any POJO.
Instead of placing the files in the appBase folder manually, place a .war file and extract it through jar command then restarting the tomcat made my application work.

JSF h tags not displaying [duplicate]

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 5 years ago.
Using Netbeans to deploy a web app on Glassfish 3.1.2.2 and none of my h tags display on the web. For instance:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html">
<head>
<title>Draft Savvy Beers</title>
</head>
<h:form>
<h:body>
<h1>Search for beers</h1>
<p><strong>Would you like to search for a beer?</strong>
<h:inputText value="#{draftSavvyController.searchTerm}" />
<h:commandButton value="#{draftSavvyController.searchforBeers}" /></p>
</h:body>
</h:form>
</html>
displays only the text, no input field or button. Using plain old html shows the fields and buttons obviously, but I can't access my controller this way. Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Let me know if I can provide anymore info. I'm pretty new at this...
Add this to your web.xml:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
I think the cause of the problem is that the request is not being passed through the FacesServlet.
The page URL did not match the url-pattern of the FacesServlet, thus it had not any chance to parse the tags.

Resources