0

i cannot find out what i am doing wrong, so that my dataTable is not shown on the webpage.

The User class i created is not really complicated but has more than these three properties which i try to set in the bean.

The only thing that is displayed is the facet Text "Test Header"

What am i missing?

Testmonitor .xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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">
    <head>
        <title>Test Monitor</title>
        <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
    </head>
    <body onload="#{testdata.createUsers()}">
        <p:dataTable id="overviewTable" var="collector" sortOrder="descending" value="#{testdata.userList}">

            <f:facet name="header">
                Test Header
            </f:facet>

            <p:column headerText="IP">
                <h:outputText value="#{collector.ip}" />
            </p:column>

            <p:column headerText="CollectorID">
                <h:outputText value="#{collector.collectorId}" />
            </p:column>     

            <p:column headerText="ID">
                <h:outputText value="#{collector.id}" />
            </p:column>                                        


        </p:dataTable>
    </body>
</html>

Bean:Testdata.java

package MonitorTest;


import UserAndPosition.User;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.util.List;


@ManagedBean
@SessionScoped
public class Testdata {

    private List<User> UserList;
    private User aUser=new User();

    public void createUsers() {
        aUser.setCollectorId("AnyCollectorID");
        aUser.setId("WND9L320NDUD");
        aUser.setIp("192.168.2.1");

        UserList.add(aUser);
        //System.out.println("Post Construct durchgelaufen");

    }
    /**
     * Regular Getter- and Setter Methods.
     */
    public Testdata() {
    }

    public List<User> getUserList() {
        return UserList;
    }

    public void setUserList(List<User> UserList) {
        this.UserList = UserList;
    }

}

Thanks in advance

joarhem
  • 1
  • 2

2 Answers2

1

I haven't tested, but you definitely need h:head and h:body instead.

Also in onload you can use only script (not Expression Language), annotate createUsers() with @PostConstruct instead - then the method will run whenever the bean is being created.

Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
  • Hey Jaqen thx for the reply.. I changed the head to h:head and the body to h:body. Furthermore the @PostConstruct annotation was implemented, but still no change. – joarhem Mar 06 '15 at 14:35
0

I found the solution: Before the error I changed the project properties in Netbeans so that not the index.xhtml would show up as initial page. i just entered "/Testmonitor.xhtml" as relative path. the "/faces" path of the url was then missing an all JSF or primefaces components did not show up (even though i did not get any error message or so..)

I dont know why this "/faces" in the url is so important, but obviously it is!

Can someone explain what /faces causes?

joarhem
  • 1
  • 2