I want to generate second selecOneMenu content when the user triggers an event on the first selecOneMenu, but it doesn't work.
当用户在第一个selecOneMenu上触发一个事件时,我希望生成第二个selecOneMenu内容,但它不起作用。
Here is the navigation rule in face-config.xml
这是faces -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
这是我的索引页面:当我点击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>
my Inscription_user.xml
我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_
我的豆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.
有一个解决方案通过移除方向上的初始化列表从方法inscription_fournisseur contact_ bean类上(),并使其在organisation_ bean类的默认构造函数,在这种情况下,但是我不喜欢这个解决方案,我更喜欢第一个场景,请帮助我。
1 个解决方案
#1
2
-
youre using the wrong namespace
<f:ajax>
should be<p:ajax>
您使用了错误的名称空间
应该 。 -
Instead u should change
update
to update what you want and set the selected value in a method defined by thelistener
to change your other selectMenu's data相反,您应该更改更新,以更新您想要的内容,并在侦听器定义的方法中设置所选的值,以更改其他selectMenu的数据。
see the showcase example
看到展示的例子
#1
2
-
youre using the wrong namespace
<f:ajax>
should be<p:ajax>
您使用了错误的名称空间
应该 。 -
Instead u should change
update
to update what you want and set the selected value in a method defined by thelistener
to change your other selectMenu's data相反,您应该更改更新,以更新您想要的内容,并在侦听器定义的方法中设置所选的值,以更改其他selectMenu的数据。
see the showcase example
看到展示的例子