Primefaces dataTable с commandButton отправляет несколько запросов в спящий режим

Я новичок в Primifaces и JSF framework. Я использую PRimefaces 5, JSF 2, Spring 4 и Hibernate 5.

Проблема, с которой я столкнулся, заключается в том, что при добавлении кнопки в dataTable количество запросов на переход в спящий режим увеличивается (избыточный запрос).

вот моя страница xthml:

<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;
}
}

здесь вывод журнала:

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

Перед загрузкой выбранной строки для отображения диалогового окна таблица данных несколько раз входит в метод getboxList ().

Я ожидаю увидеть только один запрос на действие

при загрузке страницы:

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

Что мне не хватает?

Спасибо за вашу помощь и ваше время!


person Shalom Ohayon    schedule 26.12.2014    source источник
comment
@BalusC спасибо за ваш ответ, но конкретно, какие изменения мне нужно сделать. Я пытаюсь использовать аннотацию \ @PostContruct, как описано в вашем ответе, но это не работает, у меня те же проблемы. Вторая проблема - это метод getBoxList, если я попытаюсь проверить, как предложено в ссылке, если список уже заполнен, тогда я получу ленивое исключение (сеанс, связанный с ComponentSet)   -  person Shalom Ohayon    schedule 28.12.2014
comment
@BalusC действительно благодарен вам за ваше время, я поместил бизнес-логику в сеттер для boxList, и теперь он работает, я вижу только один запрос ... но теперь я столкнулся с новой проблемой из метода setSelectedBox, когда я пытаюсь инициализировать Lazy: Вызвано: org.hibernate.HibernateException: коллекция не связана ни с одним сеансом. Еще раз спасибо за вашу помощь.   -  person Shalom Ohayon    schedule 28.12.2014
comment
Я нашел обходной путь (?) Для моего последнего комментария (ленивая проблема), изменив область действия managedBean на ViewAccessScoped   -  person Shalom Ohayon    schedule 28.12.2014