I’m a beginning Java EE programmer having troubles setting up my first “JSF 2.0” enabled application. I’m using the following technologies:
jdk1.6.0_24
MyEclipse 10.0
Glassfish 3.0.1
JSF 2.0
Problem: I couldn’t find a way to make my server parse and render JSF 2.0 pages. I followed various guides, (notably from stackoverflow.com) without success. My test pages are not rendered by Glassfish 3.0.1. I tried different approaches to fix my code including:
1 -> web.xml
1.1 -> edited header specifying JFS 2.0 HTML taglib attributes ( ..)
<?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">
1.2 – Defined JSF servlet and other stuff
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<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>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</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>/register.xhtml</url-pattern>
</servlet-mapping>
2 -> Verified many times to check if the request URL used matches the url-pattern of the FacesServlet.
**Target page** (url was not typed in browser . . . ): register.xhtml
**URL Pattern:**
<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>/register.xhtml</url-pattern>
</servlet-mapping>
3 -> home page
3.1.1 -> included header specifying JFS 2.0 HTML taglib attributes ( ..)
<!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">
4 – libraries & dependencies
Started my project with Maven 2.0 support . This is my pom.xml file:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>JSF2.0_Template_1</groupId>
<artifactId>JSF2.0_Template_1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name></name>
<description></description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.sun.el</groupId>
<artifactId>el-ri</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>bean-validator</artifactId>
<version>3.0-JBoss-4.0.2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.annotation</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.enterprise.deploy</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.jms</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.management.j2ee</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.resource</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.security.auth.message</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.security.jacc</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet.jsp</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.transaction</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api-osgi</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>webservices-api-osgi</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-osgi-bundle</artifactId>
<version>1.0.1-SP3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 – Glassfish results
5.1 - HTML JSF 2.0 Code:
<!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>A Simple JavaServer Faces Registration Application</title>
</h:head>
<h:body>
<h:form>
<h2>JSF Registration App</h2>
<h4>Registration Form</h4>
<table>
<tr>
<td>First Name:</td>
<td>
<h:inputText label="First Name"
id="fname" value="#{userBean.firstName}"
required="true"/>
<h:message for="fname" />
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<h:inputText label="Last Name"
id="lname" value="#{userBean.lastName}"
required="true"/>
<h:message for="lname" />
</td>
</tr>
<tr>
<td>Sex:</td>
<td>
<h:selectOneRadio label="Sex"
id="sex" value="#{userBean.sex}" required="true">
<f:selectItem itemLabel="Male" itemValue="male" />
<f:selectItem itemLabel="Female" itemValue="female" />
</h:selectOneRadio>
<h:message for="sex" />
</td>
</tr>
<tr>
<td>Date of Birth:</td>
<td>
<h:inputText label="Date of Birth"
id="dob" value="#{userBean.dob}" required="true">
<f:convertDateTime pattern="MM-dd-yy" />
</h:inputText> (mm-dd-yy)
<h:message for="dob" />
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<h:inputText label="Email Address"
id="email" value="#{userBean.email}" required="true"
validator="#{userBean.validateEmail}"/>
<h:message for="email" />
</td>
</tr>
<tr>
<td>Service Level:</td>
<td>
<h:selectOneMenu label="Service Level"
value="#{userBean.serviceLevel}">
<f:selectItem itemLabel="Medium" itemValue="medium" />
<f:selectItem itemLabel="Basic" itemValue="basic" />
<f:selectItem itemLabel="Premium" itemValue="premium" />
</h:selectOneMenu>
</td>
</tr>
</table>
<p><h:commandButton value="Register" action="confirm" /></p>
</h:form>
</h:body>
</html>
5.2 - HTML of page displayed by browser:
<!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"><head>
<title>A Simple JavaServer Faces Registration Application</title></head><body>
<form id="j_idt6" name="j_idt6" method="post" action="/JSF2.0_Template/faces/register.xhtml;jsessionid=db8f214e61a90013726b072f83eb" enctype="application/x-www-form- urlencoded">
<input type="hidden" name="j_idt6" value="j_idt6" />
<h2>JSF Registration App</h2>
<h4>Registration Form</h4>
<table>
<tr>
<td>First Name:</td>
<td><input id="j_idt6:fname" type="text" name="j_idt6:fname" />
</td>
</tr>
<tr>
<td>Last Name:</td>
<td><input id="j_idt6:lname" type="text" name="j_idt6:lname" />
</td>
</tr>
<tr>
<td>Sex:</td>
<td><table id="j_idt6:sex">
<tr>
<td>
<input type="radio" name="j_idt6:sex" id="j_idt6:sex:0" value="male" /><label for="j_idt6:sex:0"> Male</label></td>
<td>
<input type="radio" name="j_idt6:sex" id="j_idt6:sex:1" value="female" /><label for="j_idt6:sex:1"> Female</label></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><input id="j_idt6:dob" type="text" name="j_idt6:dob" /> (mm-dd-yy)
</td>
</tr>
<tr>
<td>Email Address:</td>
<td><input id="j_idt6:email" type="text" name="j_idt6:email" />
</td>
</tr>
<tr>
<td>Service Level:</td>
<td><select name="j_idt6:j_idt21" size="1"> <option value="medium" selected="selected">Medium</option>
<option value="basic">Basic</option>
<option value="premium">Premium</option>
</select>
</td>
</tr>
</table>
<p><input type="submit" name="j_idt6:j_idt26" value="Register" /></p><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-3247001945221977595:-4814431455900353505" autocomplete="off" />
</form></body>
</html>
I could not upload a PRINTSCREEN of what is showed by browser, but tags are not rendered.
Question: what was my mistake? What should be done to make Glassfish application server render JSF 2.0 enabled pages correctly? I just need a simple JSF 2.0 template to setup my development environment and use as start point of JSF applications.
Thanks!
In contrary to what you're telling, the JSF page is correctly rendered. As per the obtained HTTP response, the generated HTML output looks all fine. All JSF tags are correctly parsed and rendered. If JSF did not render anything, then you would have seen exactly the original JSF source code in View Source.
Your concrete problem is that the browser is not displaying the generated HTML properly. This can happen when the Content-Type header is wrong. The Content-Type header tells the browser how to interpret the content. The behaviour is also browser dependent. If you for example serve a <DOCTYPE html ...> with a Content-Type of application/xhtml+xml to the MSIE browser, then it will go havoc and even pop a confusing Save As dialogue.
In your case, even though you didn't state the problem clearly, nor described the real response in detail, nor has shown a screenshot (even though on a different host), I think that your concrete problem is that all that HTML is displayed with a Content-Type of text/plain. I.e. you're literally seeing the entire HTML source code as browser response and you misinterpreted it as "JSF not rendering the response" while it's actually your browser who didn't render the retrieved JSF-generated HTML source into a visual representation.
The right Content-Type is by default set by the JSF implementation itself, but it can be overridden by the server or even a proxy (like Apache HTTPD) in the front, or by explicitly specifying it in the JSF source code. I'm not sure about the exact cause in your particular case, but the following should force JSF to send the response explicitly as text/html.
<f:view contentType="text/html">
Put at least h:body here.
</f:view>
You can examine the response headers in any modern web browser debugging tool. For example, in Firebug:
Unrelated to the concrete problem, your FacesServlet mapping should be more generic than alone this page, or you may run into trouble when serving resources like Ajax javascripts. I recommend *.xhtml. I also recommend to redo the configuration based on a more decent tutorial. You can find good tutorials in the bottom of our JSF wiki page.
Related
This question already has answers here:
Submitting a form by pressing enter without a submit button
(20 answers)
Closed 1 year ago.
After deploy this code i go to browser and put some data in input field and press enter. It should add text to chips but it doesn't i don't have idea why plaease help.
xhtml code
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Chips</title>
</h:head>
<h:body>
Chips
<br/>
<h:form>
<h:panelGrid columns="2">
<p:outputLabel value="Add Color"/>
<p:chips />
<p:outputLabel for="display" value="Avaiable Colors"/>
<p:chips id="display" value="#{colors.colors}"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
I use this java class for xhtml with use JSF and PrimeFaces.
#ViewScoped
#Data
#Named
public class Colors implements Serializable{
private List<String> colors;
#PostConstruct
public void init() {
colors = new ArrayList<>();
colors.add("Red");
colors.add("Blue");
colors.add("Green");
colors.add("Yellow");
colors.add("Orange");
colors.add("Purple");
}
}
This is my pom.xml file maybe here something is missing. Please help it's look everything fine.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.mz</groupId>
<artifactId>Primefaces-YtTutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jakarta.jakartaee-api.version>8.0.0</jakarta.jakartaee-api.version>
<microprofile.version>3.0</microprofile.version>
<mockito-core.version>3.1.0</mockito-core.version>
<junit-jupiter.version>5.5.0</junit-jupiter.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakarta.jakartaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>${microprofile.version}</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>11.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
<build>
<finalName>Primefaces-YtTutorial</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
I add not visible commandButton and this start work corectly. But i hope someone will show me beter why to solve this issue or will point some bug in my code. I leave my solution here.
<h:form>
<h:panelGrid columns="2">
<p:outputLabel value="Add Color"/>
<p:chips/>
<p:outputLabel for="display" value="Avaiable Colors"/>
<p:chips id="display" value="#{colors.colors}"/>
</h:panelGrid>
<p:commandButton rendered="false"/>
</h:form>
I work with PrimeFaces 5.2.
These are my maven dependencies:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
I have the XHTML:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head />
<h:body>
<h:outputLabel>Name:</h:outputLabel>
<h:form>
<p:spinner />
</h:form>
</h:body>
</f:view>
</html>
The output screen is
How do I have to configure my project to see the spinner?
I think you should read the documentation for a spinner in Primefaces. Spinner is primarily used to increment/decrement the value of input text. You also need to create a bean defining the setter/getter for the values.
Do have a look https://www.primefaces.org/showcase/ui/input/spinner.xhtml
Just for reference:
<h:outputLabel for="basic" value="Basic Spinner: " />
<p:spinner id="basic" value="#{spinnerView.number1}" />
Hope it helps!!
I am getting started with JSF and trying out the following tutorial in Eclispe:
http://javing.blogspot.de/2013/01/how-to-create-new-jsf-21-project-and.html
I have got it working so that it compiles and deploys on JBoss EAP 6 without error. But I am not getting any output from my managed bean class, which consists of only one function which simply returns a text string. Here are the code files:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<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>
<welcome-file-list>
<welcome-file>home.xhtml</welcome-file>
</welcome-file-list>
</web-app>
home.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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>www.javing.blogspot.com</title>
</h:head>
<h:body>
<h:outputText value="#{hello.message}"/>
</h:body>
</html>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org
/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zeeshan.www</groupId>
<artifactId>myJSFTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>JSF Test App</name>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.6-jbossorg-2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
and the managed Bean class
package myJSFTest;
import javax.faces.bean.ManagedBean;
#ManagedBean(name="hello")
public class Hello {
public String getMessage()
{
System.out.println("Hello world function called");
return "www.javing.blogspot.com";
}
}
I have verified via static output that it is indeed the managed bean class which is not returning any output.How to solve this issue?
Enclose the outputTextcomponent inside a h:form tag:
<h:form>
<h:outputText value="#{hello.message}"/>
</h:form>
You can also choose to omit outputText all together and just place only EL expression in your page and it will work fine:
#{hello.message}
JSF 2.2 has new namespaces , it could be that your xhtml's are not rendering the components due to this. Could you correct the namepsace in xhtml as follows and give it a try,
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">
</html>
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.
I couldn't see neither primefaces nor html components in my page. I can see only "sdaf" string. What can be the problem? At index.xhtml page autocomplete works good I can see component names. There must be nothing wrong with libraries.
My index.xhtml file;
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:button value="html button"> </h:button>
sdaf
<p:spinner />
</h:body>
</html>
my pom.xml file;
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven- v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>5454</groupId>
<artifactId>45454</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>45454 Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>45454</finalName>
</build>
</project>
Try this code to see whether you can see inputtext box and a command button,
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>Title Goes Here</title>
</f:facet>
</h:head>
<h:body>
<h:form>
<p:panel header="Send">
<p:inputText value="Hi"></p:inputText>
<p:commandButton value="Send" id="btnDisplay"/>
</p:panel>
</h:form>
</h:body>
</f:view>
</html>
Web.xml
You need to have the below lines in your web.xml file
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Problem could be your 'URL' if in your web.xml you have mapping:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>`
then you need to add 'faces' to your url. For example:
:http://localhost:8080/ABC/faces/pages/login.xhtml
The reason is because you have not rendered the requested api like jsf-impl to your pom.xml for reference check Primefaces-Maven-Example
Try to put your elements to show on page into the form tag:
<h:form>
<h:button value="html button"> </h:button>
sdaf
<p:spinner/>
</h:form>
I made basic web service with two pages. I used primefaces lib and jsf. On my locallhost (jboss 6.x) the webpage works correctly. If I deployed it to openshift It looks like on the screenshot:
Here is my pom.xml:
``
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>aj</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>aj</name>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Define the version of JBoss' Java EE 6 APIs and Tools we want to import. -->
<javaee6.with.tools.version>1.0.0.M1</javaee6.with.tools.version>
<!-- Alternatively, comment out the above line, and un-comment the line below to use version 3.0.0.Beta1-redhat-1
which is a release certified to work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 maven repository. -->
<!-- <javaee6.spec.version>3.0.0.Beta1-redhat-1</javaee6.spec.version> -->
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill of Materials (BOM). A BOM specifies
the versions of a "stack" (or a collection) of artifacts. We use this here so that we always get the correct versions of
artifacts. Here we use the jboss-javaee-6.0-with tools stack (you can read this as the JBoss stack of the Java EE 6 APIs,
with some extras tools for your project, such as Arquillian for testing) -->
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${javaee6.with.tools.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${basedir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${basedir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Has anyone got the same problem? Thanks a lot for help.
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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
index.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true">
Header
</p:layoutUnit>
<p:layoutUnit position="south" size="100" closable="true" collapsible="true">
Footer
</p:layoutUnit>
<p:layoutUnit position="west" size="250" collapsible="true">
<h:form>
<p:menu>
<p:submenu >
<p:menuitem value="home" action="#{menuBean.home()}" />
<p:menuitem value="wynik" action="#{menuBean.wynik()}" />
</p:submenu>
</p:menu>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
Welcome to PrimeFaces
</p:layoutUnit>
</p:layout>
<br />
<h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />
<br />
<h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />
</h:body>
</html>
You're attempting to access the index.xhtml. However, your faces servlet mapping indicates that it should be /context-root/faces/index.xhtml
Also note that open shift is based on JBoss AS 7, not JBoss AS 6. If you want to verify that your application will work locally you should switch to AS7.