【问题标题】:ICEfaces (JSF) 3.3.0 SelectInputText Enter Key doesn't select the Item from the listICEfaces (JSF) 3.3.0 SelectInputText Enter 键不会从列表中选择项目
【发布时间】:2018-02-27 09:52:47
【问题描述】:

我在使用 ICEfaces 3.3.0 SelectInputText 时遇到了一些问题。

以下场景:

场景 1:

  1. 在条目中键入“d”
  2. 我得到了 SelectItem 的列表。 (dummy, dummy2 ...)
  3. 现在,当我通过用鼠标左键单击“虚拟”来选择它时,分配给 selectInputText.value 的值设置为虚拟(预期行为)

场景 2:

  1. 在条目中键入“d”
  2. 我得到了 SelectItem 的列表。 (dummy, dummy2 ...)
  3. 现在,当我通过使用 courser 键滚动选择“Dummy”并按 Enter 键时,我将值设置为“d”而不是 Dummy。?

场景 3:

  1. 在条目中键入“d”
  2. 我得到了 SelectItem 的列表。 (dummy, dummy2 ...)
  3. 现在,当我通过使用 courser 键滚动选择“Dummy”并按 Ctrl + Enter Key 时,我将值设置为“Dummy”。预期行为。

我还在 selectInputText.actionListener 中添加了一个 actionListener 以查看发生了什么:

场景 2 的情况下,actionListener 被调用了两次:检查第一个 actionListener 中的值包含“d”,第二个后续调用包含“Dummy”

我知道当您没有从下拉列表中选择任何内容并按下 Enter 键时,该值将设置为在 selectInputText 中输入的文本,这也是预期的行为,并且已记录在案,但在我的案例场景2 为什么actionListener调用了两次?即第一次调用时按回车键没有选中项目?

这是一个错误还是我错过了什么?

提前致谢!

代码如下:

                    <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>

这里是 Bean 的相关部分(范围=会话)

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);
}   

【问题讨论】:

    标签: jsf autocomplete icefaces


    【解决方案1】:

    场景 2 行为的原因是 IceFaces 生命周期以及事件的处理方式。听众总是被调用两次。

    考虑到您在侦听器中使用此代码,它的执行是由事件触发的。事件有一个阶段,它告诉框架您希望在生命周期的哪个部分处理它们

    您可以通过谷歌搜索“JSF 生命周期”阅读更多关于生命周期的信息

    对于您的特殊“问题”,您必须检查正确的阶段并设置值(将其放在侦听器方法的开头):

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

    【讨论】:

    • 感谢您提供信息,但这并没有太大帮助。我在 event.setPhaseId() 行设置断点,但断点从未在此断点处停止。在我发布第一篇文章之前,我已经使用过 PhaseId,但它始终是 INVOKE_APPLICATION。
    • 您的评论是一个很好的提示。 (2 次通话)。我刚刚重新实现了我的代码,现在我得到了我想要的东西。谢谢!
    猜你喜欢
    • 2021-01-30
    • 1970-01-01
    • 2016-07-20
    • 2013-04-16
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    相关资源
    最近更新 更多