2013-04-29 60 views
0

我想在用户在第一个selecOneMenu上触发事件时生成第二个selecOneMenu内容,但它不起作用。PrimeFaces p:ajax event =“change”not fired

这里是面对-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> 

这里是我的索引页:whene我对点击S'inscrire它启动第一个列表,重定向我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> 

我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> 

这里是我的豆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"; 
    } 



} 

我的豆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); 


    } 




} 

有一个解决方案通过去除方法inscription_fournisseur()在contact_ bean类方向列表中的初始化,并使它在organisation_bean类的默认构造函数中,在这种情况下它可以工作,但我不喜欢这个解决方案,我更喜欢第一种情况,请帮助我。使用了错误的命名空间<f:ajax>

+0

我看不到任何地方的''。你是故意省略那一点还是它实际上不存在于你的代码中? – kolossus 2013-04-29 16:02:11

+0

没有它出现在我的代码中(只是为了不发布很多代码行) – solarie 2013-04-29 16:09:37

+0

这是整个难题中非常重要的一部分,它的缺席或存在对最终的解决方案意味着很多。你有多个,他们是嵌套? – kolossus 2013-04-29 16:11:36

回答

2
  1. 您选择应该是<p:ajax>

  2. 代替ü应该改变update更新你想要什么,并在由listener定义的方法设置选定的值来改变你的其他selectMenu的数据

看到showcase example

+0

我已经发布了整个代码,实际上我使用的是p:ajax标签,即使我删除了它的更改事件,它不起作用,谢谢回复 – solarie 2013-04-29 16:25:29

+0

@NickHol 1.命名空间是正确的,因为事实上OP使用了<'。 2.有'change'事件,但如展示它可以省略,因为它基本上是默认的。 – skuntsel 2013-04-29 16:29:32

+0

@skuntsel他的topicname指出:p:ajax,那么他的第一篇文章就是使用f:ajax .. 是代码真的不可读。奇怪的是,你downvote我.. solarie,从你的类名称中删除'_',告诉我们'SelectedDirection'是什么(为什么大写S?),并在页面顶部放一个看它是否显示任何错误。因为你应该至少能够看到系统。 – 2013-04-29 16:35:14