datatable, fonctionnement etrange
Bonjour,
j'utilise une datatable pour afficher divers données mais j'ai remarqué que la datatable faisait plusieurs fois appel au getter pour obtenir la liste a afficher.
ma jsp : j'ai supprimé ce qui ne me paraisait pas utile
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<%--BODY--%>
<div id="body">
<h:dataTable id="Account" width="100%" value="#{AccountManagedBean.accountEntityList}" var="uneLigne" rules="rows" >
<h:column>
<f:facet name="header">
<h:outputText value="numero de compte"/>
</f:facet>
<h:form>
<h:commandLink action="#{AccountManagedBean.showDetails}">
<h:outputText value="#{uneLigne.account}"/>
</h:commandLink>
</h:form>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="description"/>
</f:facet>
<h:outputText value="#{uneLigne.description}"/>
</h:column>
</h:dataTable>
</div>
</body> |
Losque j'affiche ma jsp j'ai deja fais 3 appels au getter de la liste :
Code:
1 2 3 4 5
|
10:49:42,484 INFO [STDOUT] UserAccountsBean constructor
10:49:42,484 INFO [STDOUT] getAccountEntityList
10:49:42,505 INFO [STDOUT] getAccountEntityList
10:49:42,515 INFO [STDOUT] getAccountEntityList |
mon bean:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
@Stateful
public class UserAccountsBean implements UserAccountsBeanLocal {
@PersistenceContext(unitName ="Mes_Tables")
private EntityManager em;
private UserAccountsEntity userAccountsEntity = new UserAccountsEntity();
public UserAccountsBean() {
System.out.println("UserAccountsBean constructor");
}
public void populate(){
ici je rempli ma base pour les tests
}
public UserAccountsEntity getUserAccountEntity(String login){
Query query = em.createQuery("SELECT a FROM UserAccountsEntity a WHERE a.login=:login");
query.setParameter("login", login);
int a=0;
try {
//TODO single result
userAccountsEntity=(UserAccountsEntity)query.getResultList().get(0); //.getSingleResult();
a=userAccountsEntity.getAccountsEntity().size();
}
catch (NoResultException nre){
}
return userAccountsEntity;
}
} |
et mon managedbean :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
public class AccountManagedBean {
@EJB
private UserAccountsBeanLocal userAccountsBean;
private UserAccountsEntity userAccountsEntity = new UserAccountsEntity();
private final Principal user;
public AccountManagedBean() {
/*Save the principal's user*/
FacesContext fc = FacesContext.getCurrentInstance();
user = fc.getExternalContext().getUserPrincipal();
}
public String showDetails() {
System.out.println("showDetails");
FacesContext fc = FacesContext.getCurrentInstance();
HtmlDataTable selectedAccount = (HtmlDataTable) fc.getViewRoot().findComponent("Account");
AccountEntity account = (AccountEntity)selectedAccount.getRowData();
if(account!=null) {
System.out.println("selected account ="+account.getId());
}
return "showDetails";
}
public List<AccountEntity> getAccountEntityList() {
System.out.println("getAccountEntityList");
userAccountsBean.populate();
userAccountsEntity = userAccountsBean.getUserAccountEntity(user.getName());
List<AccountEntity> maliste = new ArrayList<AccountEntity>();
maliste= userAccountsEntity.getAccountsEntity();
return maliste;
}
} |
Et lorsque je fais appel a showDetails, la c'est le ponpon je fais au moins 15 appels au getter de la liste.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
11:05:15,663 INFO [STDOUT] getAccountEntityList
11:05:15,673 INFO [STDOUT] getAccountEntityList
11:05:15,685 INFO [STDOUT] getAccountEntityList
11:05:15,693 INFO [STDOUT] getAccountEntityList
11:05:15,702 INFO [STDOUT] getAccountEntityList
11:05:15,709 INFO [STDOUT] getAccountEntityList
11:05:15,715 INFO [STDOUT] getAccountEntityList
11:05:15,715 INFO [STDOUT] getAccountEntityList
11:05:15,725 INFO [STDOUT] getAccountEntityList
11:05:15,735 INFO [STDOUT] getAccountEntityList
11:05:15,745 INFO [STDOUT] getAccountEntityList
11:05:15,755 INFO [STDOUT] getAccountEntityList
11:05:15,765 INFO [STDOUT] getAccountEntityList
11:05:15,775 INFO [STDOUT] getAccountEntityList
11:05:15,785 INFO [STDOUT] getAccountEntityList
11:05:15,785 INFO [STDOUT] showDetails
11:05:15,785 INFO [STDOUT] selected account =3
11:05:15,805 INFO [STDOUT] getAccountEntityList
11:05:15,805 INFO [STDOUT] getAccountEntityList
11:05:15,825 INFO [STDOUT] getAccountEntityList |
est ce normal ???