I have a Maven project with JSF framework.I want to extract data from the database to dataTable. But I don't extract. I will share my codes. But these codes works correctly normal Jsf web application (not maven).
It is jpa controller class
public class usersController {
EntityManager em;
EntityManagerFactory emf;
private List<Users> users = new ArrayList<>();
public usersController() {
emf = Persistence.createEntityManagerFactory("com.ozgur_MavenJSF_war_1.0-SNAPSHOTPU");
em = emf.createEntityManager();
em.getTransaction().begin();
}
public List<Users> getUsers() {
try {
users = em.createNamedQuery("Users.findAll", Users.class).getResultList();
return users;
} catch (Exception e) {
return users;
}
}
}
It is Managed Beans class
@Named(value = "usersBeans")
@SessionScoped
public class usersBeans implements Serializable {
private List<Users> users = new ArrayList<>();
private usersController userController = new usersController();
public usersBeans() {
}
public List<Users> getAll() {
users = userController.getUsers();
return users;
}
}
It is xhtml file
<h:form>
<h:dataTable value="#{usersBeans.getAll()}" var="users">
<h:column>
<f:facet name = "header">Id</f:facet>
#{users.id}
</h:column>
<h:column>
<f:facet name = "header">Name</f:facet>
#{users.userName}
</h:column>
<h:column>
<f:facet name = "header">Surname</f:facet>
#{users.userSurname}
</h:column>
<h:column>
<f:facet name = "header">Address</f:facet>
#{users.userAddress}
</h:column>
<h:column>
<f:facet name = "header">Phone</f:facet>
#{users.userPhone}
</h:column>
</h:dataTable>
</h:form>
persistence.xml is correct
In xhtml file, <h:dataTable value="#{usersBeans.getAll()}" var="users">
Even If I write something ridiculous in value, it does not give an error. I just see an empty table. But these codes works correctly normal Jsf Web app.
Thank you in advance for your help.