In a JSF 2.1 application, I need to build a JSF dataTable
(using PrimeFaces) that shows only the db records belonging to the logged in user.
So, I need to pass the username to the bean associated to the dataTable's value
attribute:
value="#{tableBuilder.records}"
Here is the table bean:
@ManagedBean
@ViewScoped
public class TableBuilder {
private List<MyRecord> records;
private String username;
// getters and setters
}
It's useful to know that the application consists of a single web page, with container-managed authentication implemented through LoginBean
, a SessionScoped ManagedBean. This implies the additional effort of notifying to TableBuilder when the user logs in.
The only way I am thinking of is to inject the LoginBean
into the TableBuilder
through @ManagedProperty
annotation, and checking on every request of getRecords
if the username property of LoginBean has changed.
Maybe there are better ways?