jsfautocompleteicefaces

ICEfaces (JSF) 3.3.0 SelectInputText Enter Key doesn't select the Item from the list


I am having some issues with ICEfaces 3.3.0 SelectInputText.

Following scenarios:

scenario 1:

  1. typing "d" in the entry
  2. I get the list of the SelecItems. (Dummy, dummy2 ...)
  3. now when I select "Dummy" by clicking it with the left mouse key, the value aissigned to selectInputText.value is set to Dummy (expected behavior)

scenario 2:

  1. typing "d" in the entry
  2. I get the list of the SelecItems. (Dummy, dummy2 ...)
  3. now when I select "Dummy" by scrolling with the courser-key on it and press Enter Key, I get the value set to "d" and not Dummy.?

scenario 3:

  1. typing "d" in the entry
  2. I get the list of the SelecItems. (Dummy, dummy2 ...)
  3. now when I select "Dummy" by scrolling with the courser-key on it and press Ctrl + Enter Key, I get the value set to "Dummy". expected behavior.

I also add a actionListener to the selectInputText.actionListener to see what is going on:

in case of scenario 2 the actionListener called two times: checking the value in the first actionListener contains "d" and second following call contains "Dummy"

I know when you don't select anything from the drop-list and press the Enter-key, the value is set to the text entered in the selectInputText, which is also a expected behavior and is as documented, but in my case scenario 2 Why does the actionListener called two times? That is, the item is not selected by pressing Enter key at the first call?

Is this a Bug or did I miss something?

Thanks in advance!

Here is the code:

                    <ice:selectInputText

                        value="#{controller.selectedText}"
                        actionListener="#{controller.doSubmitText}"
                        textChangeListener="#{controller.textChangedEvent}"
                        rows="0" 
                        width="300"
                        listVar="person"
                        listValue="#{controller.persons}"> 
                        <f:facet name="selectInputText">
                            <h:panelGrid id="f"
                                columns="2" width="100%"
                                columnClasses="col75,col25">
                                <ice:outputLabel value="#{person.name}"/>
                                <ice:outputLabel value="#{person.username}"/>
                            </h:panelGrid>
                        </f:facet>
                    </ice:selectInputText>

and here is the related part of the Bean (scope=session)

private List<SelectItem> persons;
public List<SelectItem> getPersons() {
    return persons;
}

public void setPersons(List<SelectItem> persons) {
    this.persons= persons;
}

private String selectedText = null;

public String getSelectedText() {
    return selectedText;
}

public void setSelectedText(String selectedText) {
    this.selectedText = selectedText;
}

public void textChangedEvent(TextChangeEvent ev) {
    personlist = getfilteredList(ev.getNewValue().toString());
}

public void doSubmitText(ActionEvent event) {
    System.out.println(selectedText);
}   

Solution

  • The reason for your Scenario 2 behavior are the IceFaces Life Cycles and how events are processed. Listeners are alwayes called two times.

    Considering you are using this code in a listener, its execution has been triggered by an event. Events have a phase which tell the framework in which part of the lifecycle you want them to be processed

    You can read some more about the Lifecycles by googleing "JSF lifecycle"

    For your special "problem" you have to check correct phase and set the value (put this at the beginnig of your listener method):

    if (!event.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
            event.setPhaseId(PhaseId.INVOKE_APPLICATION);
            event.queue();
            return true;
        }