1 Reply Latest reply on Jun 29, 2006 11:47 AM by R D

    MyFaces 1.1.1: Incorrect order to call valueChangeListener a

    R D Newbie

      Hello everybody

      I am new to this forum and new to MyFaces.

      I have created the following JSF page:

      <h:selectOneMenu id="vertragid" required="true"
      value="#{rufnummerEditBean.vertragid}"
      onchange="submit()" immediate="true"
      valueChangeListener="#{rufnummerEditBean.changeVertragid}">
      <f:selectItems value="#{rufnummerEditBean.vertragidList}"/>
      </h:selectOneMenu>
      <h:selectOneMenu id="tarifid" required="true"
      value="#{rufnummerEditBean.tarifid}"
      onchange="submit()" immediate="true"
      valueChangeListener="#{rufnummerEditBean.changeTarifid}">
      <f:selectItems value="#{rufnummerEditBean.tarifidList}"/>
      </h:selectOneMenu>

      The associated code is:

      public List getVertragidList() {
      if(debugInfo) System.out.println("getVertragidList.1");
      List result=new ArrayList();
      for(Vertrag vertrag:vertragDAO.findAll()) {
      result.add(new SelectItem(
      vertrag.getId(),vertrag.getBezeichnung())
      );
      }
      if(debugInfo) System.out.println("getVertragidList.2");
      return result;
      }
      public void changeVertragid(ValueChangeEvent event) {
      Integer newval=(Integer)(event.getNewValue());
      if(debugInfo) System.out.println("changeVertragid "+newval);
      setVertragid(newval);
      List listTarifs=getTarifidList();
      if(listTarifs.isEmpty()) setTarifid(null);
      else setTarifid((Integer)(listTarifs.get(0).getValue()));
      }
      public Integer getVertragid() {
      if(debugInfo) System.out.println("getVertragid "+vertragid);
      return vertragid;
      }
      public void setVertragid(Integer vertragid) {
      if(debugInfo) System.out.println("setVertragid "+vertragid);
      this.vertragid = vertragid;
      }
      public Integer getTarifid() {
      if(debugInfo) System.out.println("getTarifid "+tarifid);
      return tarifid;
      }
      private void setTarifid(Integer tarifid) {
      if(debugInfo) System.out.println("setTarifid "+tarifid);
      this.tarifid = tarifid;
      }

      When I choose some value in the combo box Vertragid, the following messages are logged:

      13:22:13,203 INFO [STDOUT] getVertragidList.1
      13:22:13,437 INFO [STDOUT] getVertragidList.2
      13:22:13,437 INFO [STDOUT] getVertragid 470
      13:22:13,453 INFO [STDOUT] getTarifidList.1 vertragid=470
      13:22:13,796 INFO [STDOUT] getTarifidList.2 size=1
      13:22:13,796 INFO [STDOUT] getTarifid 10000460
      13:22:13,796 INFO [STDOUT] changeVertragid 10000000
      13:22:13,796 INFO [STDOUT] setVertragid 10000000
      13:22:13,796 INFO [STDOUT] getTarifidList.1 vertragid=10000000
      13:22:14,093 INFO [STDOUT] getTarifidList.2 size=1
      13:22:14,093 INFO [STDOUT] setTarifid 10000450
      13:22:17,296 INFO [STDOUT] getVertragidList.1
      13:22:17,515 INFO [STDOUT] getVertragidList.2
      13:22:17,687 INFO [STDOUT] getTarifidList.1 vertragid=10000000
      13:22:18,031 INFO [STDOUT] getTarifidList.2 size=1

      In other words, the MyFaces engine first gets the value of tarifid, then calls the valueChangeListener -changeVertragid- (which in this case modifies the value of tarifid), then gets the new value of tarifid no more.

      It is the first time I see such strange behaviour. Is this the expected behaviour?

      Regards,
      RaduDumi

        • 1. Re: MyFaces 1.1.1: Incorrect order to call valueChangeListen
          R D Newbie

          I have installed JBoss 4.0.4.GA today. (I had JBoss 4.0.4.cr2 previously.) I keep on using the default MyFaces libraries contained in JBoss.

          It's getting even stranger:

          Sometimes, when I choose some value from the combo box Vertragid, not only changeVertragid gets called, but also changeTarifid.

          Can you please help me get over these problems?