我有一个xhtml页面,它使用支持bean来获取它的信息。在这个支持bean中,我有一个用@PostConstruct
注释定义的方法。但是这个方法永远不会被调用,我无法弄清楚为什么。日志不会显示任何错误。
我正在使用Java EE 7和Payara 5.181。
我尝试了以下事项:
这是我的代码:
moderator.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:p="http://primefaces.org/ui"
>
<h:head>
<title>Moderator Pagina</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
</h:head>
<h:body>
<p:dataTable var="user" value="#{moderatorManager.twitterUsers}">
<p:column headerText="Username">
<h:outputText value="#{user.username}" />
</p:column>
</p:dataTable>
</h:body>
</html>
ModeratorManager.java
package com.guido.web;
import com.guido.models.TwitterUser;
import com.guido.services.ModeratorService;
import java.io.Serializable;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@SessionScoped
public class ModeratorManager implements Serializable {
@Inject
ModeratorService moderatorService;
private Set<TwitterUser> twitterUsers;
@PostConstruct
public void init() {
System.out.println("Postconstruct method is called!"); // <-- This does not show up in the server log.
twitterUsers = moderatorService.getUsersWithRole();
System.out.println("Initialized moderatorManager: " + twitterUsers.toString()); // <-- This does not show up in the server log.
}
public Set<TwitterUser> getTwitterUsers() {
return twitterUsers;
}
public void setTwitterUsers(Set<TwitterUser> twitterUsers) {
this.twitterUsers = twitterUsers;
}
}