I have the following JSF page:
<h:head>
<title>Admin Page</title>
</h:head>
<h:body>
<h1>Users List</h1>
<h:dataTable value="#{adminBean.linkArr}" var="o" >
<h:column>
<f:facet name="header">User name</f:facet>
#{o.username}
</h:column>
</h:dataTable>
</h:body>
And a managed bean like this:
@ManagedBean(name="adminBean")
@SessionScoped
public class AdminBean {
private static UserLink[] linkArr;
public AdminBean() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
HttpSession session = request.getSession();
String values[] = (String[])request.getSession().getAttribute("userList");
int userNos = values.length;
linkArr = new UserLink[userNos];
for(int i = 0; i < userNos; ++i) {
String tmp = values[i];
linkArr[i] = new UserLink(tmp);
}
}
public UserLink[] getLinkArr() {
return linkArr;
}
public static class UserLink {
public String username;
public UserLink(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
}
}
What I am actually trying to do is:
Save some data from a previously called servlet by creating a session. Assuming that a managed session bean is only created when its associated XHTML file is called, I am getting the attributes from the session object and using then to populate a JSF table.
However, instead of a JSF table, I am getting the following output:
Users List
User name #{o.username}
Am I assuming a wrong lifecycle for a managed session bean or there is some problem in my JSF page?