2

the queer problem i'm facing is that my setpropertyActionListener passes the value of the previous Item rather than the current one after doing a search my list.

here's my SSCCE :

<rich:dataTable cellpadding="0" cellspacing="0" border="0"
                    var="item" value="#{collaborateurBeans.list}"
                    style="text-align:center;" rows="15" width="100%"
                    styleClass="adminlist" rowClasses="row0,row1"
                    columnsWidth="10,10,10,10,,,20,170,,115"  reRender="ds" id="tableEntities">
                    <f:facet name="header">
                        <rich:columnGroup>
                            <rich:column colspan="10">
                                <h:outputText value="Collaborateur(s) found(s): #{collaborateurBeans.size}" />
                            </rich:column>
                            <rich:column breakBefore="true">
                                <h:selectBooleanCheckbox id="checkAll" styleClass="headerText"
                                    value="" onclick="checkAll()" />
                            </rich:column>
                            <rich:column>
                                <h:outputText styleClass="headerText" value="id" />
                            </rich:column>
                            <rich:column>
                                <h:outputText styleClass="headerText" value="Trig" />
                            </rich:column>
                            <rich:column>
                                <h:outputText styleClass="headerText" value="DAS" />
                            </rich:column>
                            <rich:column>
                                <h:outputText styleClass="headerText" value="Prenom" />
                            </rich:column>
                            <rich:column>
                                <h:outputText styleClass="headerText" value="Nom" />
                            </rich:column>
                            <rich:column>
                                <h:outputText styleClass="headerText" value="Ligne de Service" />
                            </rich:column>              
                            <rich:column>
                                <h:outputText styleClass="headerText" value="E-mail" />
                            </rich:column>          
                            <rich:column>
                                <h:outputText styleClass="headerText" value="Statut" />
                            </rich:column>      
                            <rich:column>
                                <h:outputText styleClass="headerText" value="Action" />
                            </rich:column>
                        </rich:columnGroup>
                    </f:facet>
                    <rich:column>
                        <h:selectBooleanCheckbox value="#{item.checked}"
                            onclick="isChecked(this.checked)">
                        </h:selectBooleanCheckbox>
                    </rich:column>
                    <rich:column sortBy="#{item.iidcollaborateur}" sortOrder="DESCENDING"
                        style="text-align:center">
                        <h:outputText value="#{item.iidcollaborateur}" />
                    </rich:column>
                    <rich:column filterBy="#{item.strTrigrammeCollaborateur}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.strTrigrammeCollaborateur}" />
                    </rich:column>
                    <rich:column filterBy="#{item.strDascollaborateur}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.strDascollaborateur}" />
                    </rich:column>
                    <rich:column filterBy="#{item.strPrenomCollaborateur}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.strPrenomCollaborateur}" />
                    </rich:column>
                    <rich:column filterBy="#{item.strNomCollaborateur}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.strNomCollaborateur}" />
                    </rich:column>
                    <rich:column filterBy="#{item.rrLigneservice.strLigneService}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.rrLigneservice.strLigneService}" />
                    </rich:column>
                    <rich:column filterBy="#{item.strEmailCollaborateur}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.strEmailCollaborateur}" />
                    </rich:column>
                    <rich:column filterBy="#{item.rrStatutcollaborateur.strLibelleStatutCollaborateur}" filterEvent="onkeyup"
                        style="padding-left:10px">
                        <h:outputText value="#{item.rrStatutcollaborateur.strLibelleStatutCollaborateur}" style='width:100%;display:block;height:15px;
                background-color:#{item.rrStatutcollaborateur.strCouleur == "" ? "" 
                                    :item.rrStatutcollaborateur.strCouleur}'/>
                    </rich:column>
                    <rich:column style="text-align:center">

                    <a4j:commandLink id="tooltip">
                            <h:graphicImage value="../images/actions/tooltip.png"
                                style="border:0px;padding-right:5px" alt="view">
                            </h:graphicImage>
                        </a4j:commandLink>
                        <rich:toolTip for="tooltip" showDelay="300" direction="top-left"
                            styleClass="tooltip" layout="block">
                            <a4j:outputPanel layout="block">
                                <h:panelGrid columns="4">
                                    <f:facet name="header">
                                        <h:outputText value="Collaborateur Détails:" style="text-align:center;"/>
                                    </f:facet>

                                    <h:outputText value="Collaborateur :" />
                                    <h:outputText value="#{item.strNomCollaborateur} #{item.strPrenomCollaborateur}"
                                        styleClass="tooltipData" />
                                    <h:outputText value="DAS :" />
                                    <h:outputText value="#{item.strDascollaborateur}" 
                                        styleClass="tooltipData" />                                 
                                    <h:outputText value="Date Naissnace : " styleClass="tooltipData" />
                                    <h:outputText value="#{item.dtDateNaissanceCollaborateur}" styleClass="tooltipData" >
                                        <f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="Europe/Paris"/>
                                    </h:outputText>
                                    <h:outputText value="Adresse :" />
                                    <h:outputText value="#{item.strAdresseCollaborateur}" 
                                        styleClass="tooltipData" />
                                    <h:outputText value="Email :" />
                                    <h:outputText value="#{item.strEmailCollaborateur}" 
                                        styleClass="tooltipData" />
                                    <h:outputText value="Télephone :" />
                                    <h:outputText value="#{item.strTelephoneProfessionelCollaborateur}" 
                                        styleClass="tooltipData" />
                                    <h:outputText value="Etage :" />
                                    <h:outputText value="#{item.strEtageCollaborateur}" 
                                        styleClass="tooltipData" />
                                        <h:outputText value="Bureau :" />
                                    <h:outputText value="#{item.strBureauCollaborateur}" 
                                        styleClass="tooltipData" />
                                    <h:outputText value="Ligne de Service :" />
                                    <h:outputText value="#{item.rrLigneservice.strLigneService}" 
                                        styleClass="tooltipData" /> 
                                    <h:outputText value="Responsable :" />
                                    <h:outputText value="#{item.rrCollaborateur.strNomCollaborateur} #{item.rrCollaborateur.strPrenomCollaborateur}" 
                                        styleClass="tooltipData" />     
                                    <h:outputText value="Date D'Arrivé prévue :" />
                                    <h:outputText value="#{item.dtDateArriveePrevueCollaborateur}"
                                        styleClass="tooltipData" >
                                        <f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="Europe/Paris"/>
                                    </h:outputText>
                                    <h:outputText value="Date De Sortie Prévue :" />
                                    <h:outputText value="#{item.dtDateSortiePrevueCollaborateur}"
                                        styleClass="tooltipData">
                                        <f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="Europe/Paris"/>
                                    </h:outputText>
                                    <h:outputText value="Date D'Arrivé Réelle :" />
                                    <h:outputText value="#{item.dtDateArriveReelleCollaborateur}"
                                        styleClass="tooltipData">
                                        <f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="Europe/Paris"/>
                                    </h:outputText>
                                    <h:outputText value="Date De Sortie Réelle :" />
                                    <h:outputText value="#{item.dtDateSortieReelleCollaborateur}"
                                        styleClass="tooltipData">
                                        <f:convertDateTime pattern="dd/MM/yyyy" type="date" timeZone="Europe/Paris"/>
                                    </h:outputText>
                                    <h:outputText value="Niveau :" />
                                    <h:outputText value="#{item.rrNiveau.strLibelleNiveau}"
                                        styleClass="tooltipData" />
                                    <h:outputText value="Code D'Emploi :" />
                                    <h:outputText value="#{item.rrCodeemploi.strLibelleCodeEmploi}"
                                        styleClass="tooltipData" />     

                                    <h:outputText value="Fonction :" />
                                    <h:outputText value="#{item.rrFonction.strTitreFonction}"
                                        styleClass="tooltipData" />
                                    <h:outputText value="Statut :" />
                                    <h:outputText value="#{item.rrStatutcollaborateur.strLibelleStatutCollaborateur}"
                                        styleClass="tooltipData" />


                                </h:panelGrid>
                            </a4j:outputPanel>
                        </rich:toolTip>
                        <h:commandLink action="#{collaborateurBeans.redirectEdit}" title="editer"
                            onclick="blur();">
                            <h:graphicImage value="../images/actions/edit.png"
                                style="border:0px;padding-right:5px" alt="Edit" />
                            <f:setPropertyActionListener value="#{item}"
                                target="#{suiviBridgeBean.collaborateur}" />
                            <f:setPropertyActionListener value="#{item}"
                                target="#{collaborateurBeans.currentItem}"/>
                        </h:commandLink>
                        <h:commandLink action="#{collaborateurBeans.redirectSuivi}" title="ajouter suivi"
                            onclick="blur();">
                            <h:graphicImage value="../images/actions/suivi.png"
                                style="border:0px;padding-right:5px" alt="Suivi"/>
                            <f:setPropertyActionListener value="#{item}"
                                target="#{suiviBridgeBean.collaborateur}" />
                        </h:commandLink>
                        <h:commandLink action="#{collaborateurBeans.redirectDetail}"
                                    title="Détail des affectations" onclick="blur();">
                                    <h:graphicImage value="../images/actions/detailed.png"
                                        style="border:0;padding-right:5px" alt="Détail" />
                                    <f:setPropertyActionListener value="#{item}"
                                        target="#{benchBridgeBean.rrCollaborateur}" />
                        </h:commandLink>
                        <h:commandLink action="#{collaborateurBeans.deleteItem}" title="supprimer"
                            onclick="blur();if(!confirm('voulez-vous supprimer le collaborateur selectionné ?')) return false;">
                            <h:graphicImage value="../images/actions/delete.png"
                                style="border:0" alt="Delete" />
                            <f:setPropertyActionListener value="#{item}"
                                target="#{collaborateurBeans.currentItem}" />
                        </h:commandLink>
                    </rich:column>
                    <f:facet name="footer">
                        <rich:datascroller id="ds" renderIfSinglePage="false" maxPages="10" page="1"
                        onclick="ajaxStart()" oncomplete="ajaxStop()" ajaxSingle="true"></rich:datascroller>
                    </f:facet>
                </rich:dataTable>

my backing bean :

public class CollaborateurBeans extends MsgBox {

        private CollaborateurManager collaborateurManager;// contrat de service
    private List<RrCollaborateur> list;// Liste des collaborateurs utilisé meme
                                        // dans la recherche
    private List<RrCollaborateur> listAll;// affiche tout les collaborateurs

    private NiveauCodeEmploiManager niveauCodeEmploiManager;// contrat de
    // service
    private List<RrNiveaucodeemploi> listNiveau;// List niveau correspondant à
                                                // un code emloi

    private RrCollaborateur currentItem;// Ligne selectionnées

    // ** Attribut de recherche **//
    private RrCollaborateur collaborateurSearch;// info sur collaborateur
    private Date dtArriveeReelleLo;
    private Date dtArriveeReelleHi;
    private Date dtSortieReelleLo;
    private Date dtSortieReelleHi;
    // ** **//

    private Integer idResponsable = 0;// Id du responsable du collaborateur

        public CollaborateurBeans() {
        collaborateurManager = (CollaborateurManager) ApplicationContext
                .getApplicationContext().getBean("collaborateurManager");
        niveauCodeEmploiManager = (NiveauCodeEmploiManager) ApplicationContext
                .getApplicationContext().getBean("niveauCodeEmploiManager");
        currentItem = new RrCollaborateur();
        collaborateurSearch = new RrCollaborateur();
        // initialisation des messages
        super.msgError = null;
        super.msgSuccess = null;

    }


        public String redirectEdit() {
        if (currentItem.getRrCollaborateur() != null)
            idResponsable = currentItem.getRrCollaborateur()
                    .getIidcollaborateur();
        return "success";
    }

}

the probleme occurs in this line

<f:setPropertyActionListener value="#{item}"
                                    target="#{collaborateurBeans.currentItem}"/>
                            </h:commandLink>

the item is the current item in the datatable , everything works well when i try to edit a row , but when i search and retreive another list with a more limited size , the setProperty action listenr passes the item of the previous list , i realy don't know how that happens because

<h:outputText value="#{item.iidcollaborateur}" styleClass="tooltipData" />

displays the right Id.

even after rerendering my dataTable it still passes the id's of the previous list result. i realy don't get it . my backBean's scope is "request" .

any thoughts?

Genjuro
  • 7,405
  • 7
  • 41
  • 61
  • 1
    The code posted so far looks fine. Your problem is caused elsewhere. Please post an SSCCE. My first guess would be incorrect datatable value preserving logic. – BalusC Nov 09 '11 at 02:11
  • when i changed the scope of backing bean to be session , it works fine , i don't know why :D – Genjuro Nov 09 '11 at 13:15
  • 1
    That only confirms my guess more :) – BalusC Nov 09 '11 at 13:16
  • eventhough it works well , i do get a "Target Unreachable" exception from time to time . – Genjuro Nov 14 '11 at 11:06
  • turning my backing beans's scopes into session , generated some problemes , i've edited my Question with an SSCCE, can you please take a peek ? thank you – Genjuro Nov 29 '11 at 14:54
  • Sorry, that's not really an SSCCE. It's not copy'n'paste'n'runnable in a blank playground environment without doing other major changes. As to your problem, how does your `getList()` method look like? It just returns the list and does nothing else, right? I do not see anywhere in your code where you're preserving/managing the list. – BalusC Nov 29 '11 at 15:13
  • the getList() retrieves the List from another service , but yeah it just returns the list. please note if i turn my backing bean into session scope in faces-config.xml , it works , and the editing no longer uses the previous item – Genjuro Nov 29 '11 at 15:34

1 Answers1

1

As per the comments:

the getList() retrieves the List from another service

So,

public List<RrCollaborateur> getList() {
    return someService.list();
}

This is not correct. You should not do any business job in getter methods. You need to load and assign that list only in bean's (post)constructor or any action event methods.

private List<RrCollaborateur> list;

public CollaborateurBeans() {
    list = someService.list();
}

public void someUpdateAction() {
    someService.update(someItem);
    list = someService.list();
}

public List<RrCollaborateur> getList() {
    return list;
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thanks for the best practise but unfortunetly thi doesn't resolve my problem , in fact i tried to display the current UserId in each of my Datable : it displays the correct id , but when i hit edit , it uses the id of the previous list. somehow the setPropertyListener behaves in a weird way , in the jsf the value is correct but in the setter when i debug , the value is wrong . when i turn the backing bean scope in session it works worrectly , but i wanna avoid messing with the scopes. – Genjuro Nov 29 '11 at 16:05
  • 1
    The `f:setPropertyActionListener` doesn't run during the HTTP request when the page is displayed to the browser. It only runs in the next HTTP request when you submit a form in that page. In a request scoped bean you need to ensure that **exactly the same** list is been preserved as it was in the previous request during displaying the page. – BalusC Nov 29 '11 at 16:08
  • thanks man indeed i had to make my List static for it to preserve its value , because i'm using the same backing bean for the editing as well , so the constructor was initialising the list on each request. – Genjuro Nov 29 '11 at 16:43
  • 1
    The list shouldn't be `static`. It would be shared application wide among all requests in all sessions. – BalusC Nov 29 '11 at 16:44
  • ohh u r right .what do you suggest then ? to avoid it initilizes on each request – Genjuro Nov 29 '11 at 16:50
  • 1
    If you're using JSF 2.0, put bean in view scope. If you're using RichFaces, use `` to simulate JSF 2.0 view scope. If you're using Tomahawk, use `` to simulate JSF 2.0 view scope. – BalusC Nov 29 '11 at 16:53
  • works like a charm , thank you so much man :) issue officialy resolved =) – Genjuro Nov 29 '11 at 17:09