I am new with Primifaces and JSF framework I am using PRimefaces 5, JSF 2, Spring 4 and Hibernate 5
The problem that I am facing is that when adding a button into dataTable the number of request to hibernate increase ( redundant request ).
here my xthml page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<p:outputLabel value="Boitiers"/>
<h:form prependId="false">
<p:dataTable var="box" value="#{boxListView.boxList}" lazy="true" paginator="true" rows="20">
<p:column headerText="Box Id">
<h:outputText value="#{box.id}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{box.name}" />
</p:column>
<p:column headerText="MAC">
<h:outputText value="#{box.mac}" />
</p:column>
<p:column headerText="Ip Externe">
<h:outputText value="#{box.ipExt}" />
</p:column>
<p:column headerText="IPv4">
<h:outputText value="#{box.ipv4}" />
</p:column>
<p:column headerText="IPv6">
<h:outputText value="#{box.ipv6}" />
</p:column>
<p:column headerText="Version">
<h:outputText value="#{box.version}" />
</p:column>
<p:column headerText="MAJ">
<h:outputText value="#{box.maj}" />
</p:column>
<p:column headerText="Current Version">
<h:outputText value="#{box.currentVersion}" />
</p:column>
<p:column headerText="Users">
<p:commandButton value="Details" update="@([id$=display])" oncomplete="PF('userDialog').show()" icon="ui-icon-extlink" >
<f:setPropertyActionListener value="#{box}" target="#{boxListView.selectedBox}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- rendered="#{not empty boxListView.selectedBox}" -->
<p:dialog header="Users for box ID:" widgetVar="userDialog" resizable="false" minHeight="40" modal="true">
<p:outputPanel id="display" style="text-align:center;">
<p:dataTable var="user" value="#{boxListView.userBoxList}" tableStyle="width:auto" lazy="true">
<p:column>
<f:facet name="header">
<h:outputText value="User Id" />
</f:facet>
<h:outputText value="#{user.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nom" />
</f:facet>
<h:outputText value="#{user.nom}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Prenom" />
</f:facet>
<h:outputText value="#{user.prenom}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="email" />
</f:facet>
<h:outputText value="#{user.email}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
</h:form>
</h:body>
my ManagedBean class:
@SuppressWarnings("serial")
@ManagedBean
//@ViewAccessScoped
public class BoxListView extends LazyDataModel<Box> implements Serializable
{
@ManagedProperty(value = "#{boxService}")
private IBoxService boxService;
private Box selectedBox;
List<User> users = new ArrayList<User>();
public IBoxService getBoxService() {
return boxService;
}
public void setBoxService(IBoxService boxService) {
this.boxService = boxService;
}
public Box getSelectedBox() {
return selectedBox;
}
public void setSelectedBox(Box selectedBox)
{
this.selectedBox = selectedBox;
if(this.selectedBox == null)
return ;
boxService.initializeLazy(selectedBox.getBoxUsers());
Set<BoxUser> userbox = selectedBox.getBoxUsers();
if(userbox != null)
{
for (BoxUser boxUser : userbox)
{
users.add(boxUser.getUser());
}
}
}
public List<Box> getboxList()
{
if(boxService == null)
return null;
return boxService.findAll();
}
public List<User> getUserBoxList()
{
return users;
}
}
here log output:
INFO: Server startup in 48378 ms
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'boxService'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'transactionManager'
<==========================================================>
<--- Here i am loading the page the retrieve all my box ----->
<--- We can see that 2 same request are sent ----->
<--- This problem doesn't occurred if I remove the button from the datatable ----->
<==========================================================>
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory'
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'boxService'
<==========================================================>
<--- Here i am clicking the button ----->
<==========================================================>
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
boxusers0_.idbox as idbox2_0_0_,
boxusers0_.id as id1_1_0_,
boxusers0_.id as id1_1_1_,
boxusers0_.idbox as idbox2_1_1_,
boxusers0_.iduser as iduser3_1_1_,
user1_.id as id1_22_2_,
user1_.code_postal as code_pos2_22_2_,
user1_.email as email3_22_2_,
user1_.nom as nom4_22_2_,
user1_.pass as pass5_22_2_,
user1_.prenom as prenom6_22_2_,
user1_.role as role7_22_2_,
user1_.telephone as telephon8_22_2_
from
box_user boxusers0_
left outer join
users user1_
on boxusers0_.iduser=user1_.id
where
boxusers0_.idbox=?
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
Before loading the selected row to display the dialog box the datatable is entering the method getboxList() several time.
I am expecting to see only one request per action
when loading the page:
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
and when clicking the button:
Hibernate:
select
this_.id as id1_0_1_,
this_.current_version as current_2_0_1_,
this_.idtest as idtest3_0_1_,
this_.ip_ext as ip_ext4_0_1_,
this_.ipv4 as ipv5_0_1_,
this_.ipv6 as ipv6_0_1_,
this_.last_conf_changed as last_con7_0_1_,
this_.last_connection as last_con8_0_1_,
this_.mac as mac9_0_1_,
this_.idmaj as idmaj15_0_1_,
this_.name as name10_0_1_,
this_.plcbus as plcbus11_0_1_,
this_.reinit as reinit12_0_1_,
this_.triphase as triphas13_0_1_,
this_.version as version14_0_1_,
maj2_.id as id1_8_0_,
maj2_.active as active2_8_0_,
maj2_.date as date3_8_0_,
maj2_.descriptif as descript4_8_0_,
maj2_.nom as nom5_8_0_,
maj2_.stable as stable6_8_0_
from
box this_
left outer join
maj maj2_
on this_.idmaj=maj2_.id
What I am missing ?
Thanks for your help and your time !