データを表示するためのテストを行っています。私は、自分のユーザ名を見て+歌った後、他のユーザのデータを見るようにします。基本的に、アプリケーションはデータベースにユーザーを保存し、別の形式で自分のユーザー名を表示することに進みます。この2番目の形式では、表内に他のユーザー名を表示できません。私は何をすべきか分かりません。どういうわけかtry/catchブロックでこのメソッドを実装しますか?Hibernate、Springを使用してxhtml DataTableにデータを表示できません。
汎用ダオインタフェース:
DAO実装:
package com.example.j2eeapp.dao;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.example.j2eeapp.test.BasicView;
@Component
@Transactional
public abstract class DaoImpl <T, ID extends Serializable> implements Dao<T,ID> {
private Class<T> persistentClass;
private EntityManager entityManager;
public DaoImpl(Class<T> persistentClass) {
this.persistentClass = persistentClass;
}
protected EntityManager getEntityManager() {
return entityManager;
}
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public Class<T> getPersistentClass() {
return persistentClass;
}
public T save(T entity) {
getEntityManager().persist(entity);
return entity;
}
@SuppressWarnings("unchecked")
public List<T> findAll() {
return getEntityManager()
.createQuery("from " + getPersistentClass().getSimpleName())
.getResultList();
}
}
public void flush() {
getEntityManager().flush();
}
public List<T> getfindUserName(){
return findUserName();
}
}
XHTML形式:
<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/templates/general.xhtml">
<ui:define name="title"><h:outputText value="Success" /></ui:define>
<ui:define name="header"><h:outputText value="Success" /></ui:define>
<ui:define name="content">
<h:form id="successForm">
<p:fieldset styleClass="fieldset" legend="Succcess">
<h:panelGrid columns="1" cellpadding="5">
<h:outputText id="display" value="#{basicView.userName}" />
<p:dataTable var="usersDetails" value="#{daoImpl.findAll}">
<p:column headerText="Id">
<h:outputText value="#{usersDetails.id}" />
</p:column>
<p:column headerText="User Name">
<h:outputText value="#{usersDetails.userName}" />
</p:column>
<p:column headerText="Password">
<h:outputText value="#{usersDetails.password}" />
</p:column>
<p:column headerText="Last name">
<h:outputText value="#{usersDetails.lastName}" />
</p:column>
<p:column headerText="First name">
<h:outputText value="#{usersDetails.firstName}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</p:fieldset>
</h:form>
</ui:define>
感謝を。私はあなたが書いたことをしましたが、テーブルには "レコードが見つかりません"と表示され、ログには何も関係しません(エラーメッセージなし)。私は私の質問を編集しました。アドバイスをお願いしますか?よろしく。 –
@A.Luk私の更新を参照してください。これがあなたに役立つことを願っています – questionare
これで問題は解決しましたか? – questionare