I have get the solution ; the problem was in the Scope the right one is @ViewScoped.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Insert title here</title>
</h:head>
<h:body>
<h:form id="create_intervention_form">
<h:messages id="errorMessages" style="color:red;margin:8px;" />
<table>
<tr>
<td><p:outputLabel value="Matricule:" for="Matricule" /></td>
<td><p:inputText id="Matricule"
value="#{teststation.matricule}" size="5" /></td>
</tr>
<tr>
<td><h:outputLabel value="Structure à visiter:" for="Client2"></h:outputLabel> </td>
<td>
<p:panel id="st">
<p:selectOneMenu id="Client2" value="#{teststation.selected_client}">
<f:selectItems value="#{teststation.list_client}" var="cl" itemValue="#{cl}" itemLabel="#{cl.nom_client}" />
<f:converter converterId="ClientConverter" />
<p:ajax update="station1_client" listener ="#{teststation.getStructureByClient}" />
</p:selectOneMenu>
<p:selectOneMenu id="station1_client" value="#{teststation.selectedStation}" >
<f:attribute name="selected_station" value="#{teststation.selectedStation}" />
<f:selectItems value="#{teststation.list_Station}" var="entry1" itemValue="#{entry1}" itemLabel="#{entry1.nom_stat}" />
<f:converter converterId="StationConverter" />
</p:selectOneMenu>
</p:panel>
</td>
</tr>
<tr>
<td><h:outputLabel value="Immatriculation:" for="imma"></h:outputLabel> </td>
<td><p:inputText size="20" value="#{teststation.immatriculation}" id="imma"></p:inputText></td>
</tr>
<tr>
<p:growl id="growl" life="2000" />
<td></td>
<td><p:commandButton value="Valider" id="valide" update="errorMessages" actionListener="#{teststation.addOdm}" styleClass="ui-priority-primary" />
</td>
</tr>
</table>
</h:form>
</h:body>
</html>
the ManagedBean
@ViewScoped
@ManagedBean(name = "teststation")
public class TestStation {
private String matricule;
private stationService stationService = new stationServiceImpl();
private clientService clientService = new clientServiceImpl();
public static Logger log = LogManager.getLogger(CreerIntervention.class.getName());
private String nom;
private String client_name;
private List<client> list_client;
private List<station> list_Station;
private List<SelectItem> clientList;
//private Map<String, String> clientList;
//private Map<String, String> stationList;
private List<SelectItem> stationList;
private String immatriculation;
private String ref_Selected_client;
private String Nom_Selected_client;
private String ref_Selected_station;
private String Nom_Selected_station;
private List<station> station;
private station selectedStation;
private client Selected_client;
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
Map<String, String> selectedStationParam= fc.getExternalContext().getRequestParameterMap();
@PostConstruct
public void initMyBean()
{
log.info("ici PosteConstract"+this.getClass().hashCode());
}
public TestStation()
{
super();
log.info("ici Constract "+this.getClass().hashCode());
}
{
list_client = clientService.findAll();
}
public void updateSelectedStation()
{
log.info("LES updateSelectedStatio ---"+ list_Station.get(0).getNom_stat());
}
public void getStructureByClient()
{
log.info("La refernce du client selectioné est --- "+ Selected_client.getRef());
list_Station=stationService.findByRefClient(getSelected_client().getRef());
stationList= new ArrayList<>();
for (station o : list_Station)
{
stationList.add(new SelectItem(o.getNom_stat(),o.getRef_stat()));
}
log.info("LES STIONS SONT D UN NBR DE ---"+ list_Station.get(0).getNom_stat());
}
public void addOdm()
{ Nom_Selected_station=selectedStation.getNom_stat();
//log.info("num_odm :" + num_odm) ;
log.info("Matricule:" + matricule) ;
log.info("client:"+Selected_client.getNom_client()) ;
log.info("station:"+ Nom_Selected_station);
log.info("imma:"+ immatriculation) ;
}
public void addMessage(String summary) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void cancelAction(ActionEvent e)
{
log.info("etat valeur ShowForm555 = ");
}
public String getMatricule() {
return matricule;
}
public void setMatricule(String matricule) {
this.matricule = matricule;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getNom_Selected_client() {
return Nom_Selected_client;
}
public void setNom_Selected_client(String nom_Selected_client) {
Nom_Selected_client = nom_Selected_client;
}
public String getRef_Selected_client() {
return ref_Selected_client;
}
public void setRef_Selected_client(String Ref_Selected_client) {
this.ref_Selected_client = Ref_Selected_client;
}
public String getClient_name() {
return client_name;
}
public void setClient_name(String client_name) {
this.client_name = client_name;
}
/*public Map<String, String> getClientList() {
return clientList;
}
public void setClientList(Map<String, String> clientList) {
this.clientList = clientList;
}
public List<client> getList_client() {
return list_client;
}
public void setList_client(List<client> list_client) {
this.list_client = list_client;
}*/
public String getImmatriculation() {
return immatriculation;
}
public void setImmatriculation(String immatriculation) {
this.immatriculation = immatriculation;
}
public List<station> getStation() {
return station;
}
public void setStation(List<station> station) {
this.station = station;
}
/*public List<station> getList_Station() {
return list_Station;
}
public void setList_Station(List<station> list_Station) {
this.list_Station = list_Station;
}*/
/*public Map<String, String> getStationList() {
return stationList;
}
public void setStationList(Map<String, String> stationList) {
stationList = stationList;
}*/
public void setClientList(List<SelectItem> clientList) {
this.clientList = clientList;
}
public List<SelectItem> getStationList() {
return stationList;
}
public void setStationList(List<SelectItem> stationList) {
this.stationList = stationList;
}
public List<SelectItem> getClientList() {
return clientList;
}
public station getSelectedStation() {
return selectedStation;
}
public void setSelectedStation(station selectedStation) {
this.selectedStation = selectedStation;
}
public client getSelected_client() {
return Selected_client;
}
public void setSelected_client(client selected_client) {
Selected_client = selected_client;
}
public List<client> getList_client() {
return list_client;
}
public void setList_client(List<client> list_client) {
this.list_client = list_client;
}
public List<station> getList_Station() {
return list_Station;
}
public void setList_Station(List<station> list_Station) {
this.list_Station = list_Station;
}
public String getRef_Selected_station() {
return ref_Selected_station;
}
public void setRef_Selected_station(String ref_Selected_station) {
this.ref_Selected_station = ref_Selected_station;
}
public String getNom_Selected_station() {
return Nom_Selected_station;
}
public void setNom_Selected_station(String nom_Selected_station) {
Nom_Selected_station = nom_Selected_station;
}
}
the StationConverter
@FacesConverter("StationConverter")
public class StationConverter implements Converter {
public static Logger log = LogManager.getLogger(StationConverter.class.getName());
stationService statServ = new stationServiceImpl();
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
if (submittedValue == null || submittedValue.isEmpty()) {
return null;
}
try {
log.info("4- submitted value for Station Converter ********** "+submittedValue);
log.info("5- returned Object for Station Converter ********** "+statServ.findByRef(submittedValue).getNom_stat());
return statServ.findByRef(submittedValue);
} catch (NumberFormatException exception) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid Client ID"));
}}
public String getAsString(FacesContext context, UIComponent component, Object modelValue) {
if (modelValue == null) {
return "";
}
log.info(modelValue.getClass());
if (modelValue instanceof station ) {
log.info( "6- la valeur en String Converter Station est ****** "+String.valueOf(((station) modelValue).getNom_stat()));
return String.valueOf(((station) modelValue).getRef_stat());
} else {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid Station instance"));
}
}
}