【问题标题】:JSF rich:suggestionbox need to filter the suggestion list by excluding the items already selectedJSF rich:suggestionbox 需要通过排除已经选择的项目来过滤建议列表
【发布时间】:2013-01-24 14:10:41
【问题描述】:

有一个与文本框关联的 jsf 建议框。一切正常,除了我无法排除已经选择的结果。关联的文本框包含逗号分隔值。我还没有找到任何方法可以显示除了文本框中已经存在的建议之外的建议。我可以将文本框值连同建议 ajax 请求或任何其他想法一起传递吗?

public class ActionBean {

private String contacts;

public List<Contact> autocomplete(Object suggest) {

//....
// logic to get the list from DB based on suggestion but no data about existing selected values
//....

}
}

该文本框和建议框的 JSF 的 xhtml 部分

<h:inputText value="#{actionBean.contacts}" styleClass="input mFields" id="text">
    <a4j:support event="onchange" action="#{someaction...}" return;" reRender="..."/>
</h:inputText>

<h:outputLabel value="Search and Select Name/Number or Enter Number. Use , for multiple entries"/>
    <rich:suggestionbox limitToList="true" id="suggestionBoxId" for="text" tokens=",[]" suggestionAction="#{actionBean.autocomplete}" var="result" fetchValue="#{result.number}" height="100" width="200" nothingLabel="No contacts found" columnClasses="center" usingSuggestObjects="true" >
        <h:column>
            <h:outputText value="#{result.name} #{result.lastName}" />
        </h:column>
        <h:column>
            <h:outputText value="#{result.number}" style="font-style:italic" />
        </h:column>
    </rich:suggestionbox>

【问题讨论】:

    标签: jsf richfaces


    【解决方案1】:

    您必须将选定的值传递给服务器才能排除它们。也许你可以做一些 JavaScript hack,但不会更干净(参见 usingSuggestObjects 和 onobjectchange)。

    【讨论】:

      【解决方案2】:

      @Chris 感谢您的回复。

      我终于找到了方法,即将使用的 bean 设置为请求范围,因此即使通过 javasript 调用 onchange 事件也会为每个 bean 的每个请求创建方法调用。在上述情况下,建议框每次都调用一个新对象,而 inputtext 上的 onchange 也每次都调用一个新对象。

      我想出的解决方案是将 bean 范围设置为“视图”,以便该视图的 bean 对象保持不变,因此所有请求都可以共享状态。然后在建议框的 onsubmit 事件中调用 inputtext 的 onchange 事件,用 inputtext 中的最新值更新 bean 字段。

      <rich:suggestionbox limitToList="true" id="suggestionBoxId" for="text" tokens=",[]" suggestionAction="#{actionBean.autocomplete}" var="result" fetchValue="#{result.number}" height="100" width="200" nothingLabel="No contacts found" columnClasses="center" usingSuggestObjects="true" onsubmite="call onchange event on inputext field">
      

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2011-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多