简体   繁体   中英

PrimeFaces p:ajax event=“change” not fired

I want to generate second selecOneMenu content when the user triggers an event on the first selecOneMenu, but it doesn't work.

Here is the navigation rule in face-config.xml

 <navigation-rule>
     <from-view-id>/index.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{contact_.inscription_fournisseur}</from-action>
            <from-outcome>success</from-outcome>
            <to-view-id>xhtml/Inscription_user.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

here is my index page : whene i click on S'inscrire it initiates the first list and redirects me to Inscription_user.xhtml

<?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:f="http://java.sun.com/jsf/core">

  <!--  <link href="${request.contextPath}/css/style.css" rel="stylesheet" type="text/css"/>-->
    <link href="css/style.css" rel="stylesheet" type="text/css"/> 
    <script type="text/javascript" src="js/ao.js" />


    <h:head>
        <title><h:outputText value="#{En_Fr.titre_page_index_fr}"/></title>
    </h:head>
    <body class="box_center" >
        <div style="border:0px #888 solid; margin-top:40px; margin-left:10%; margin-right:10%">


        <div class="box_fournisser">

        <div class="titre_site" style="text-align:right">Accs fournisseur</div>

<div class="pwd_oublie font-label" style="text-align:right; color: #666;">  <label>Mot de passe oublié</label></div><div class="pwd_oublie font-label" style="text-align:right; text-decoration: underline;">  
<label><h:form>
              <h:commandLink action="#{contact_.inscription_fournisseur}"  styleClass="pwd_oublie font-label" style="text-align:left; margin-left: 15px; text-decoration: underline;" >
              S'inscrire
              </h:commandLink>
              </h:form>
              </label>
          </div></div>

    <div  class="statistic_ background_site_unselected  "  ><label class="nombre_statistic">1236</label><label class="label_statistic">appel d'offre</label></div>
    <div  class="statistic_ background_site_unselected  " style="top:10%" ><label class="nombre_statistic">15985</label><label class="label_statistic">demande de devis</label></div>
    <div  class="statistic_ background_site_unselected " style="top:15%" ><label class="nombre_statistic">4859</label><label class="label_statistic">visite par moi</label></div></div>



</body>
        </html>

my Inscription_user.xml

<?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:f="http://java.sun.com/jsf/core"
       xmlns:p="http://primefaces.org/ui">
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<link href="../css/inscription.css" rel="stylesheet" type="text/css"/>
    <h:head>
        <title><h:outputText value="#{En_Fr.titre_page_index_fr}"/></title>
    </h:head>
    <body>
<div></div>
  <f:view>   
            <h:form>
            <h:messages>d :</h:messages>
          <div   class="ligne_inscription" >
 <div class="label_inscription">Direction</div>
<div>
<p:selectOneMenu effect="fade" value="#{contact_.organisme.selectedDirection}" style="width:110;">
   <f:selectItem itemLabel="Select One" itemValue="0"/>
   <f:selectItems value="#{contact_.organisme.directions}" var="direction" itemLabel="#{direction.direction}" itemValue="#{direction.idDirection}"/>
<p:ajax update="lstfonct" listener="#{contact_.organisme.initFonction}" />
</p:selectOneMenu>
                </div></div>


                           <div   class="ligne_inscription" >
<div class="label_inscription">Fonction</div><div>



<p:selectOneMenu effect="fade" value="#{contact_.organisme.selectedFonction}" id="lstfonct">
  <f:selectItem itemLabel="Select One" itemValue="0"/>
  <f:selectItems value="#{contact_.organisme.fonctions}" var="fonction" itemLabel="#{fonction.fonction}" itemValue="#{fonction.idEmploi}"/>
</p:selectOneMenu>       
</div></div>  


    <h:commandButton type="submit" value="Valider"  action="#{contact_.inscription_choix_alerte()}"  />         

            </h:form>

</f:view>  

    </body>
</html>

here is my bean Contact_

package beans;
// Generated 23 oct. 2012 21:51:42 by Hibernate Tools 3.2.1.GA


import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import Dao.Emploi_dao;




/**
 * Contact generated by hbm2java
 */

@ManagedBean(name="contact_")
@RequestScoped

public class Contact_  implements java.io.Serializable {


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

     @ManagedProperty(value="#{organisme_}")
     private Organisme_ organisme;


    public Organisme_ getOrganisme() {
        return organisme;
    }


    public void setOrganisme(Organisme_ organisme) {
        this.organisme = organisme;
    }




    public String inscription_fournisseur() {
        organisme.setDirections(Emploi_dao.List_direction());
        return "success";
    }



}

my bean organisation_

package beans;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import Dao.Activite_dao;
import Dao.Emploi_dao;
import Dao.Organisme_dao;
import hibernate.Activite;
import hibernate.Adresse;
import hibernate.Emploi;
import hibernate.Organisme;



import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.event.AjaxBehaviorEvent;



/**
 *
 *
 */

@ManagedBean (name="organisme_")
@RequestScoped
public class Organisme_  implements java.io.Serializable  {
     /**
     * 
     */
    private static final long serialVersionUID = 4579411552477526993L;


     private List<Emploi> directions = new ArrayList <Emploi>(0);
     private List<Emploi> fonctions = new ArrayList <Emploi>(0);
     private String SelectedDirection;
     private String SelectedFonction;



     public List<Emploi> getDirections() {
        return directions;
    }



    public void setDirections(List<Emploi> directions) {
        this.directions = directions;
    }



    public List<Emploi> getFonctions() {
        return fonctions;
    }



    public void setFonctions(List<Emploi> fonctions) {
        this.fonctions = fonctions;
    }



    public String getSelectedDirection() {
        return SelectedDirection;
    }



    public void setSelectedDirection(String selectedDirection) {
        SelectedDirection = selectedDirection;
    }



    public String getSelectedFonction() {
        return SelectedFonction;
    }



    public void setSelectedFonction(String selectedFonction) {
        SelectedFonction = selectedFonction;
    }



    public void initFonction()
    {
        System.out.println("------------debut-----------");
         fonctions=Emploi_dao.List_fonction(SelectedDirection);


    }




}

there is one solution by removing the initialization on the directions list from the method inscription_fournisseur() on the contact_ bean class, and make it in the default constructor of the organisation_ bean class, in this case it works, but I don't prefer this solution, I prefer the first scenario, please help me.

  1. youre using the wrong namespace <f:ajax> should be <p:ajax>

  2. Instead u should change update to update what you want and set the selected value in a method defined by the listener to change your other selectMenu's data

see the showcase example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM