0

I have a form that consists of 3 dropdown and when i chose an item from the first dropdown the listener retrieve the list of the 2nd dropdown perfectly. But when i chose an item from the 2nd dropdown listener does not work and does not even mention the method of my bean.

Here is my form

                      <p:outputLabel for="structure" value="Structure"/>
                        <h:panelGroup >         
                            <p:selectOneMenu id="structure" value="#{etpBean.idt_structure}" style="margin-bottom:10px;" required="true">
                                <p:ajax listener="#{etpBean.onRessourceChange}" update="affectation" />


                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:selectItems value="#{etpBean.structures}" var="structure" itemValue="#{structure.idt_structure}" itemLabel="#{structure.nom}" />
                            </p:selectOneMenu>
                         </h:panelGroup>


                        <p:outputLabel for="affectation" value="les ressources affectee"/>
                        <h:panelGroup >         
                            <p:selectOneMenu id="affectation" value="#{etpBean.idt_affectation}" style="margin-bottom:10px;" required="true">

                                <p:ajax listener="#{etpBean.onAffectationChange}" update="activite" />

                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:selectItems value="#{etpBean.affectations}" var="affectation" itemValue="#{affectation.idt_affectation}" itemLabel="#{affectation.ressource.nom}" />
                            </p:selectOneMenu>
                         </h:panelGroup>      
                    <p:outputLabel for="activite" value="Activite"/>
                        <h:panelGroup >         
                            <p:selectOneMenu id="activite" value="#{etpBean.idt_parent}" style="margin-bottom:10px;" required="true">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:selectItems value="#{etpBean.activites}" var="activite" itemValue="#{activite.idt_parent}" itemLabel="#{activite.nom}" />
                            </p:selectOneMenu>
                         </h:panelGroup>

                    <p:outputLabel for="pes" value="charge effectué"/>
                    <h:panelGroup>
                        <p:inputText id="pes" value="#{etpBean.etp}" />
                        <p:slider for="pes" step="1" />
                    </h:panelGroup>


                            </p:panelGrid>
                        </p:panel>

     </h:form>

And Here is my bean

@ManagedBean(name="etpBean")
@ViewScoped
public class EquivalentTempPleinBean implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

private Double etp;
private Date dateDebut;
private Date dateFin;
private Long idt_affectation;
private Long idt_parent;
private Long idt_ressource;
private Long idt_structure;



private Collection<Ressource> ressources;
private Collection<Structure> structures;
private Collection<Activite> activites;
private Collection<Affectation> affectations;

private ETP equivalentTempPlein = new ETP();

private Ressource ressource = new Ressource();
private Affectation affectation;
private Activite activite = new Activite();
private Structure structure;

@ManagedProperty(value = "#{ressourceService}")
private IRessourceService ressourceService;

@ManagedProperty(value = "#{structureService}")
private IStructureService structureService;

@ManagedProperty(value = "#{activiteService}")
private IActiviteService activiteService;

@ManagedProperty(value = "#{affectationService}")
private IAffectationService affectationService;


public EquivalentTempPleinBean() {
    super();
}

@PostConstruct
public void init()
{
    structures=structureService.listStructures();
}

// work perfeclty
public void onRessourceChange(){
    System.out.println("On ressource Change");
    structure =structureService.findStructureById(idt_structure);
    affectations=affectationService.affectationByStructure(idt_structure);
    //ressources=ressourceService.ressourceOnAffectation(idt_structure);

}

//dont work
public void onAffectationChange(){
    System.out.println("##########################################################");
    affectation=(Affectation) affectationService.findAffectationById(idt_affectation);
    activites=activiteService.activiteOnAffectation(idt_structure,affectation.getDateDebut(),affectation.getDateFin());
}
//Getters and setters 
 }                    
CHARAFI Saad
  • 1,340
  • 3
  • 16
  • 36
  • 1
    do you mean that when you choose the second item it doesn't change the 3rd – Yagami Light Apr 05 '17 at 09:54
  • @YagamiLight Yes exactly !! You have an idea why? – CHARAFI Saad Apr 05 '17 at 09:56
  • 1
    maybe add an event to your ajax, the event is `event="change"` – Yagami Light Apr 05 '17 at 10:00
  • that mean every time you change your choice it will execute the listner – Yagami Light Apr 05 '17 at 10:02
  • 1
    The actual answer to this question (the one in the title) is **Yes**, but I doubt that helps you. Read http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value and try to investigate in more detail – Kukeltje Apr 05 '17 at 10:23
  • @YagamiLight Thank u for ur response i added event="change" and it works. but i have another poblem hibernate.LazyInitializationException for this line on onAffectationChange method `affectation.getDateDebut()` – CHARAFI Saad Apr 05 '17 at 10:29
  • 1
    Did you see if the value is null (by the way one question at the time) – Yagami Light Apr 05 '17 at 10:46
  • @YagamiLight the value is not null but when i try to do object.getProperty from the object that I get this error appears. – CHARAFI Saad Apr 05 '17 at 10:52

0 Answers0