0 Replies Latest reply on Dec 25, 2008 7:27 PM by Dirk Ho

    selectOneMenu with a4j:support to rerender another selectOne

    Dirk Ho Newbie


      I have two selectOneMenus. If a user selects the marke/brand of a car (e.g. BMW, VW, Mercedes), the second selectOneMenu should show the different types of cars depending on the selected marke/brand (e.g. E-Klasse, S-Klasse,...).

      I spend a whole day (and half night) on searching for results for my problem in google,... But found nothing.

      It works so far, but if I choose the type of the car, I get the following error:

      01:11:07,405 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=newUsedCar:fahrzeugTyp[severity=(ERROR 2), summary=(newUsedCar:fahrzeugTyp: Validation-error: Value is not valid.), detail=(newUsedCar:fahrzeugTyp: Validation-error: Value is not valid.)]

      This is my code in the xhtml-page

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns:a4j="http://richfaces.org/a4j"
      <ui:define name="body">
       <h:messages />
       <h:form id="newUsedCar">
      <h:outputText value="Land:" />
       <a4j:region id="filter">
       <h:panelGroup id="countryOneMenu">
       <h:selectOneMenu value="#{newUsedCarAction.marke}" id="marke">
       <s:selectItems var="marke" value="#{newUsedCarAction.markenSelect()}" label="#{marke.marke}" itemValue="#{marke.marke}" noSelectionLabel="Marke" />
       <a4j:support event="onchange" action="#{newUsedCarAction.changeTyp()}" reRender="statesOneMenu" ajaxSingle="true"/>
       <h:outputText value="Bundesstaat oder was auch immer:" />
       <h:panelGroup id="statesOneMenu">
       <h:selectOneMenu value="#{newUsedCarAction.typ}" id="fahrzeugTyp">
       <s:selectItems var="fahrzeugTyp" value="#{newUsedCarAction.getFahrzeugTypen()}" label="#{fahrzeugTyp.fahrzeugTyp}" itemValue="#{fahrzeugTyp.fahrzeugTyp}" noSelectionLabel="FahrzeugTyp" />
       <a4j:support event="onchange"/>
       <h:commandButton action="#{newUsedCarAction.sellCar()}" value="submitButton" />

      This is my entityBean

      package de.autohaus;
      import static org.jboss.seam.ScopeType.CONVERSATION;
      import java.util.Collection;
      import java.util.List;
      import java.util.ArrayList;
      import java.util.Calendar;
      import java.util.GregorianCalendar;
      import java.util.TimeZone;
      import java.util.Date;
      import javax.ejb.EJB;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.faces.model.SelectItem;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import static javax.persistence.PersistenceContextType.EXTENDED;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.log.Log;
      import de.autohaus.fahrzeugverwaltung.Fahrzeugverwaltung;
      import de.autohaus.fahrzeugverwaltung.db.Fahrzeug;
      import de.autohaus.fahrzeugverwaltung.db.FahrzeugTypNotFoundException;
      import de.autohaus.fahrzeugverwaltung.db.Marke;
      import de.autohaus.fahrzeugverwaltung.db.FahrzeugTyp;
      import de.autohaus.bestellverwaltung.Bestellverwaltung;
      import de.autohaus.benutzerverwaltung.db.Anrede;
      import de.autohaus.benutzerverwaltung.db.Kunde;
      import de.autohaus.bestellverwaltung.db.Versandart;
      public class NewUsedCarAction implements NewUsedCar {
       Log log;
       private Fahrzeugverwaltung fv;
       private Bestellverwaltung bv;
       private EntityManager em;
       private transient FacesContext facesContext;
       private Kunde kunde;
       private ArrayList<Versandart> versandarten;
       private ArrayList<Marke> marken;
       private ArrayList<FahrzeugTyp> typen;
       private String versandart;
       private Fahrzeug fahrzeug;
       private String marke;
       private String typ;
       private String verify;
       public void sellCar() {
       log.info("TYP: " + typ);
       log.info("Marke: " + marke);
       public List<Marke> markenSelect() {
       marken = new ArrayList<Marke>(fv.findAllMarken());
       return marken;
       public List<FahrzeugTyp> getFahrzeugTypen() {
       if(this.typen == null)
       this.typen = new ArrayList<FahrzeugTyp>();
       log.info("FahrzeugTypen: " + typen);
       return this.typen;
       public List<FahrzeugTyp> changeTyp() throws FahrzeugTypNotFoundException {
       typen = new ArrayList<FahrzeugTyp>(fv.findFahrzeugTypenByMarke(this.marke));
       return typen;
       public List<Versandart> versandartenSelect() {
       log.info("BV: " + bv);
       versandarten = new ArrayList<Versandart>(bv.findAllVersandarten());
       return versandarten;
       public String getTyp() {
       return this.typ;
       public void setTyp(String t) {
       this.typ = t;
       public String getMarke() {
       return this.marke;
       public void setMarke(String m) {
       this.marke = m;
       public String getVersandart() {
       return this.versandart;
       public void setVersandart(String v) {
       this.versandart = v;
       public Kunde getKunde() {
       return this.kunde;
       public void setKunde(Kunde k) {
       this.kunde = k;
       public Fahrzeug getFahrzeug() {
       return this.fahrzeug;
       public void setFahrzeug(Fahrzeug f) {
       this.fahrzeug = f;
       public String getVerify()
       return verify;
       public void setVerify(String verify)
       this.verify = verify;
       public void destroy() {}

      Something very strange is: This example works on an other page. This page is started by clicking a button <h:commandLink value="show" action="#{buyCarAction.buyCar(car)}" rendered="#{identity.loggedIn}" />. As paramter I send a Fahrzeug-Object.

      The code in the page and also of the entity are completely the same (I only changed the @Name of the bean and according in the xhtml-page). And this works perfectly...

      Thanks a lot and best regards,