Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:36:17+00:00 2026-05-25T12:36:17+00:00

i have an init() function that returns a list of Domaines needed to populate

  • 0

i have an init() function that returns a list of Domaines needed to populate a datatable, each row of this datatable have two commandlinks one for edit and another for delete, so when i press the edit command link a dialog window apear showing the Domaine information whith the possibility of editing (there is another dialog for adding new domaines), so the problem is when i press edit the init function is called 8 times then the attributes of the adding dialog are setted (even if there is no relation between the thee edit command link and the adding dialog window) after the init function is called again 4 times. i don’t understand wh.
here my page code:

    <?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
         <ui:composition template="gpsiTemplate.xhtml">
            <ui:define name="left-menu">
                <ui:include src="admin-menuGauche.xhtml" />
            </ui:define> 
            <ui:define name="top">
                <ui:include src="menu-top.xhtml" />
            </ui:define>
            <ui:define name="content-top">
                <center>
                       <f:view>
                           <h:form id="topacteurs">
                               <h:panelGrid columns="14" styleClass="adminTopTable" >
                                   <h5 class="calendar">Direction :</h5> 
                                   <p:selectOneMenu id="typeacteurs" value="#{domaine.choixDirection}" style="width: 180px">  
                                        <f:selectItem itemLabel="Direction..." itemValue="" />  
                                        <f:selectItems value="#{direction.initcomb()}"  var="ta" itemValue="#{ta.codeDirection}" itemLabel="#{ta.libelleDirection}" />
                                        <p:ajax update=":mainform:domainlist" process="topacteurs" event="change" />
                                    </p:selectOneMenu>      

                                    <p:spacer width="20" height="0" />
                                    <p:commandButton title="Ajouter un domaine" image="ui-icon ui-icon-disk" value="Ajouter un domaine"  oncomplete="ajoutDomaine.show()"/>  
                                </h:panelGrid>  
                            </h:form>
                        </f:view>
                </center>
            </ui:define>
            <ui:define name="content-content">
                <h:form id="modifform">
                    <p:dialog header="Modifier un domaine" widgetVar="editDomaine" modal="true" width="400" height="200" showEffect="clip" hideEffect="clip">
                        <p:outputPanel id="editDomaineDetails" style="text-align:center;" layout="block">
                            <center>
                                <h:panelGrid  columns="2" cellpadding="5">
                                        <h:outputLabel  value="Intitulé        :"/>
                                        <p:inputText value="#{domaine.currentDomaine.libelleDomaine}" style="width: 180px"/>
                                        <h:outputLabel  value="Respensable        :"/>
                                        <p:inputText value="#{domaine.currentDomaine.nomDirecteur}" style="width: 180px"/>
                                        <h:outputLabel  value="Direction        :"/>
                                       <p:selectOneMenu id="editchoidirection" value="#{domaine.codeDirection}" style="width: 180px">  
                                            <f:selectItem itemLabel="Direction..." itemValue="" />  
                                            <f:selectItems value="#{direction.initcomb()}"  var="ta" itemValue="#{ta.codeDirection}" itemLabel="#{ta.libelleDirection}" />
                                        </p:selectOneMenu>
                                </h:panelGrid>
                                <h:panelGrid  columns="2" cellpadding="5">
                                    <p:commandButton value="Modifier" update="messages editDomaineDetails :mainform:domainlist" actionListener="#{domaine.update()}" oncomplete="editDomaine.hide()"/>
                                    <p:commandButton value="Annuler"  oncomplete="editDomaine.hide()"/>
                                </h:panelGrid>
                            </center>
                        </p:outputPanel>
                    </p:dialog>
                </h:form>
                <h:form id="mainform">
                    <p:growl id="messages" showDetail="true"/>
                    <p:confirmDialog message="Etes-vous sure?" width="200"  
                                        showEffect="clip" hideEffect="clip"  
                                        header="Confirmation" severity="alert" widgetVar="confirmation">  

                        <p:commandButton value="Oui sure" update="messages :mainform:domainlist" actionListener="#{domaine.delete()}" oncomplete="confirmation.hide()"/>  
                        <p:commandButton value="Non" onclick="confirmation.hide()" type="button" /> 
                    </p:confirmDialog>
                    <p:dialog header="Ajouter un domaine" widgetVar="ajoutDomaine" modal="true" width="400" height="200" showEffect="clip" hideEffect="clip">
                        <p:outputPanel id="ajoutDomaineDetails" style="text-align:center;" layout="block">
                            <center>
                                <h:panelGrid  columns="2" cellpadding="5">
                                        <h:outputLabel  value="Intitulé        :"/>
                                        <p:inputText value="#{domaine.nomDomaine}" style="width: 180px"/>
                                        <h:outputLabel  value="Respensable        :"/>
                                        <p:inputText value="#{domaine.nomDirecteur}" style="width: 180px"/>
                                        <h:outputLabel  value="Direction        :"/>
                                       <p:selectOneMenu id="ajoutchoidirection" value="#{domaine.codeDirection}" style="width: 180px">  
                                            <f:selectItem itemLabel="Direction..." itemValue="" />  
                                            <f:selectItems value="#{direction.initcomb()}"  var="ta" itemValue="#{ta.codeDirection}" itemLabel="#{ta.libelleDirection}" />
                                        </p:selectOneMenu>
                                </h:panelGrid>
                                <h:panelGrid  columns="2" cellpadding="5">
                                    <p:commandButton value="Ajouter" update="messages ajoutDomaineDetails :mainform:domainlist" actionListener="#{domaine.save()}" oncomplete="ajoutDomaine.hide()"/>
                                    <p:commandButton value="Annuler"  oncomplete="ajoutDomaine.hide()"/>
                                </h:panelGrid>
                            </center>
                        </p:outputPanel>
                    </p:dialog>

                    <p:dataTable id="domainlist" var="e" value="#{domaine.init()}">
                        <p:column headerText="Intitulé" filterBy="#{e.libelleDomaine}">
                            <h:outputText value="#{e.libelleDomaine}" />
                        </p:column>
                        <p:column headerText="Directeur" filterBy="#{e.nomDirecteur}">
                            <h:outputText value="#{e.nomDirecteur}" />
                        </p:column>
                        <p:column headerText="Direction" filterBy="#{e.directions.libelleDirection}">
                            <h:outputText value="#{e.directions.libelleDirection}" />
                        </p:column>
                        <p:column>
                            <h:panelGrid columns="3" style="border-color: #ffffff">
                                <p:commandLink update=":modifform:editDomaineDetails"  title="Editer" oncomplete="editDomaine.show()">  
                                    <p:graphicImage value="resources/images/edit.png"/>   
                                    <f:setPropertyActionListener value="#{e}" target="#{domaine.currentDomaine}" />  
                                </p:commandLink>
                                <p:commandLink title="Supprimer" oncomplete="confirmation.show()">  
                                    <p:graphicImage value="resources/images/delete.png"/>   
                                    <f:setPropertyActionListener value="#{e}" target="#{domaine.currentDomaine}" />  
                                </p:commandLink>
                            </h:panelGrid>
                        </p:column>
                    </p:dataTable>
                    <p:stack icon="resources/images/stack/stck.png">  
                        <p:menuitem value="Photo" icon="resources/images/stack/photo.png" url="http://localhost:8084/Gpsi/faces/profile-Photo.xhtml"/> 
                        <p:menuitem value="Profile" icon="resources/images/stack/profile.png" url="http://localhost:8084/Gpsi/faces/profile.xhtml"/>
                        <p:menuitem value="Administration" icon="resources/images/stack/administration.png" url="http://localhost:8084/Gpsi/faces/admin.xhtml"/>

                    </p:stack>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

here the same code on Pastebin but it’s a bit messed up: http://pastebin.com/W0XGa0d2

and here is my back up bean:

......
 public List<Domaines> initComb()
{
    .....
}
 public List<Domaines> init()
 {

    if(choixDirection==0)
    {
        domaines=domainesService.getAllDomaines();
    }
    else
    {
        Directions direction=directionsService.getDirections(choixDirection);
        domaines=domainesService.getDirDomaines(direction);
    }
    return domaines;
 }
 public void save()
 {
   ......
 }
 public void delete()
 {
     ......

 }
 public void update()
 {
     ......
 }
  ////////////////////////////////////////////////////////// setters & getters \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
......
public void setCodeDirection(Integer codeDirection)
{
    this.codeDirection=codeDirection;
}
  public Integer getCodeDirection()
{
    return codeDirection;
}
  public void setNomDomaine(String nomDomaine)
{
    this.nomDomaine=nomDomaine;
}
  public String getNomDomaine()
{
    return nomDomaine;
}
   public void setNomDirecteur(String nomDirecteur)
{
    this.nomDirecteur=nomDirecteur;
}
  public String getNomDirecteur()
{
    return nomDirecteur;
}
  ......

}

i posted long codes cause don’t where the problem is coming from.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:36:18+00:00Added an answer on May 25, 2026 at 12:36 pm

    Your mistake is that you’re doing business action in a getter method instead of an action method which is called only once. You should not do business actions in getters. JSF EL uses getters to access bean properties. EL does not cache them when they’re ever called once. Getters should solely return bean properties (or at highest do some lazy loading or quick and non-intensive calculation, e.g. a simple sum like return foo + bar;), but definitely not access the database or something.

    Move that job to the constructor or @PostConstruct method or any event method of the bean. In this particular case, you likely want to use @PostConstruct to preload the list with help of an @EJB and let the ajax action listener point to the same method as well. In a @ViewScoped bean, this way it’s called only once during first request of the view and also called only once when you change the selection.

    @PostConstruct
    public void init() {
        if (choixDirection == 0) {
            domaines = domainesService.getAllDomaines();
        } else {
            Directions direction = directionsService.getDirections(choixDirection);
            domaines = domainesService.getDirDomaines(direction);
        }
    }
    
    public List<Domaines> getDomaines() {
        return domaines;
    }
    

    and fix the view accordingly

    <p:ajax process="topacteurs" listener="#{domaine.init}" update=":mainform:domainlist" />
    ...
    <p:dataTable id="domainlist" var="e" value="#{domaine.domaines}">
    

    See also:

    • Why JSF calls getters multiple times
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class: function RustEditor() { this.init = function() { var saveButton =
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
I have the following loop inside an function init(); which is executed onload, I
I have got the following very simple code: function init() { var articleTabs =
i have created a module with this among others this function in it: <?php
This is the code that I have to dynamically declaring an array inside a
I have a disordered list named d that looks like: [0.0000, 123.9877,0.0000,9870.9876, ...] I
I have an class Item that represents an item in a list. I have
I have tried to build a small function that would be use in controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.