0

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sefa Taşcan
  • 57
  • 2
  • 6
  • 1
    And your debugging reveals what? Data is in the database? Where is the JPA entity? Where is the JPA query? Is data retrieved by your JPA query? blah blah blah –  Dec 23 '17 at 13:23
  • Yes Sefa, please narrow down your problem. It is very, very rare that maven has influence on a running application. Java is waaay to broad as a tag and the chance that an issue is both JPA and JSF related is less than 1%. Split your problem in at least two parts. The DB part and JSF part. Check the JSF part if you work with a static array. And read https://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times (use a good tutorial) – Kukeltje Dec 23 '17 at 14:32
  • I dont know that where is the problem – Sefa Taşcan Dec 23 '17 at 22:06
  • That is where creating a [mcve] comes to the resque! – Kukeltje Dec 24 '17 at 12:22

0 Answers0