1 Reply Latest reply on Jun 2, 2010 11:08 AM by judy guglielmin

    Autocomplete selectInputText valueChangeListener

    asi nidi Newbie
      I am using selectInputText with autocomplete function inside a dataTable. My table has 10 rows.

      <ice:selectInputText size="13"
      maxlength="50"
      actionListener="#{cAuto.putCurrentSub(_sub)}"
      valueChangeListener="#{cAuto.updateList}"
      title="This textbox is enhanced with auto-complete functionality. Just type in the c-nr you are looking for.">
      <f:selectItems value="#{cAuto.matchesList}"/>
      </ice:selectInputText>


      Whenever user selects a value (for a field) from the auto complete listing, i have to populate the values in another fields of that row in dataTable.

      --Independ of the number of rows in the dataTable, it works only for the last row everytime and the inputvalue is cleared


      public void putCurrentSub(Sub sub)
      {
      this.currentSub = sub;
      }



      public void updateList(ValueChangeEvent event)
      {
      setMatches(event);

      if (event.getComponent() instanceof SelectInputText)
      {
      SelectInputText autoComplete = (SelectInputText) event.getComponent();
      if (autoComplete.getSelectedItem() != null)
      {
      Sub sub = (Sub) autoComplete.getSelectedItem().getValue();

      currentSub.setSub(sub);
      valueChangeEffect.setFired(false);
      }
      }

      }




      protected void setMatches(ValueChangeEvent event)
      {

      setMatchesList(new ArrayList<SelectItem>());
      String searchWord = event.getNewValue().toString();
      if (!searchWord.equals(""))
      {
      List<Sub> tempCountList = getEntityManager().createQuery("select ec from Sub ec where ec.cNo like :cNo").setParameter("cNo", searchWord + "%").getResultList();
      for (Sub sub : tempCountList)
      {
      SelectItem selectItem = new SelectItem(sub, sub.getCNo());
      if (!getMatchesList().contains(selectItem))
      {
      getMatchesList().add(selectItem);
      }
      }
      }
      }