0

i have written a jsf-spring-hibernate application just to practice using an example on web.there isn't an error on console; and when i run it on localhost, i should see this screen:

enter image description here

However, i see this:

enter image description here

i used same xhtml file as in the example file:

    <?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:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <title>JSF Spring Hibernate Integration</title>
    <style type="text/css">
.tg {
    border-collapse: collapse;
    border-spacing: 0;
    border-color: #ccc;
}

.tg td {
    font-family: Arial, sans-serif;
    font-size: 14px;
    padding: 10px 5px;
    border-style: solid;
    border-width: 1px;
    overflow: hidden;
    word-break: normal;
    border-color: #ccc;
    color: #333;
    background-color: #fff;
}

.tg th {
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    padding: 10px 5px;
    border-style: solid;
    border-width: 1px;
    overflow: hidden;
    word-break: normal;
    border-color: #ccc;
    color: #333;
    background-color: #f0f0f0;
}

.tg .tg-4eph {
    background-color: #f9f9f9
}
</style>
</h:head>
<h:body>
    <h1>Add a Person</h1>
    <h:form>
        <table>
            <tr>
                <td><label>Name</label></td>
                <td><h:inputText id="name" value="#{person.name}"></h:inputText>
                </td>
            </tr>
            <tr>
                <td><label>Country</label></td>
                <td><h:inputText id="country" value="#{person.country}"></h:inputText>
                </td>
            </tr>
            <tr>
                <td colspan="2"><h:commandButton
                        action="#{personService.addPerson(person)}" value="Add Person"></h:commandButton>
                </td>
            </tr>

        </table>

    </h:form>

    <br />
    <h3>Persons List</h3>

    <c:if test="${!empty personService.listPersons()}">
        <table class="tg">
            <tr>
                <th width="80">Person ID</th>
                <th width="120">Person Name</th>
                <th width="120">Person Country</th>
            </tr>
            <ui:repeat value="${personService.listPersons()}" var="person">
                <tr>
                    <td>${person.id}</td>
                    <td>${person.name}</td>
                    <td>${person.country}</td>
                </tr>
            </ui:repeat>
        </table>
    </c:if>

</h:body>
</html>

Why do i get a different output?

oddly
  • 260
  • 3
  • 9
  • 22

1 Answers1

1

You didn't defined it as JSF file in web.xml, thats why the file is not interpreted on the server, but send "as is" to the browser.

You need:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

in your web.xml

Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58