public List<Annonce> loadAnnonce( UserEntity idUser ) {
Query query = getEntityManger().createQuery( "select u from "
+ getPersistentClass().getSimpleName()
+ " u where u.annonceUser= :idUser" ).setParameter( "idUser", idUser );
List<Annonce> annonce = (List) query.getResultList();
return annonce;
}
文件:DaoUser.java
public UserEntity loadUserByEmail( String email ) {
Assert.notNull( email );
UserEntity user = null;
Query query = getEntityManger().createQuery( "select u from "
+ getPersistentClass().getSimpleName()
+ " u where u.email= :email" ).setParameter( "email", email );
try {
user = (UserEntity) query.getSingleResult();
} catch ( NoResultException e ) {
}
return user;
}
public Annonce annonceEnFonctionId( Annonce annonce, String email ) {
UserEntity user = userDao.loadUserByEmail( email );
List<Annonce> a = annonceDao.loadAnnonce( user );
Annonce an = annonce;
for ( int i = 0; i < a.size(); i++ ) {
if ( a.get( i ).getId() == (Long) an.getId() ) {
an = annonce;
}
}
return an;
}
<transition on="annonceID" to="annonceEnFonctionId">
<evaluate expression="userService.annonceEnFonctionId(annonce,user.getEmail())" result="flowScope.annonce" />
</transition>
<p:dataTable var="item" value="#{annonce}">
<p:column style="width:2%">
<h:commandButton value="show" action="annonceID" />
</p:column>
<p:column>
<h:outputText value="#{item.titre}" />
</p:column>
<p:dataTable var="valeur" value="#{annonce}">
<p:column headerText="Model">
<h:outputText value="#{valeur.titre}" />
</p:column>
</p:dataTable>
当我点击按钮显示时我应该获得更多关于annonce的详细信息,但我仍然总是得到DataBase中的第一个annonce任何想法?