5

使用 RichFaces 时,suggestionBox如何将多个 id 或值从带有文本输入的页面传递到suggestionBox支持 bean。即:显示所选州内的建议城市列表?这是我的autoComplete方法。

public List< Suburb > autocomplete(Object suggest)
{
    String pref = (String) suggest;
    ArrayList< Suburb > result = new ArrayList< Suburb >();

    Iterator< Suburb > iterator = getSuburbs().iterator();
    while( iterator.hasNext() )
    {
        Suburb elem = ((Suburb) iterator.next());
        if( (elem.getName() != null && elem.getName().toLowerCase().indexOf( pref.toLowerCase() ) == 0) || "".equals( pref ) )
        {
            result.add( elem );
        }
    }
    return result;
}

如您所见,从页面传递了一个值,Object建议,它是h:inputText(在 faceLets 中m:textFormRow)的文本

<m:textFormRow id="suburb" label="#{msgs.suburbPrompt}" 
    property="#{bean[dto].addressDTO.suburb}"
    required="true" maxlength="100" size="30" />

<rich:suggestionbox height="200" width="200" usingSuggestObjects="true"
    suggestionAction="#{suburbsMBean.autocomplete}" var="suburb" for="suburb"
    fetchValue="#{suburb.name}" id="suggestion">
    <h:column>
        <h:outputText value="#{suburb.name}" />
    </h:column>
</rich:suggestionbox>

在页面的前面,您可以选择我想用来减少建议框显示的郊区列表的州。

4

4 回答 4

3

(免责声明:我知道这个问题是很久以前提出的,但也许这会帮助有类似问题的人......)

查看此博客文章,其中涉及类似的内容:RichFaces - SuggestionBox and hidden field。 

关键是要使用<f:setPropertyActionListener value="#{...}" target="#{...}">wrapped inside <a4j:support event="onselect" ajaxSingle="true">onselect当为 SuggestionBox 触发时,这可用于设置支持 bean 的附加值。

通过这种方法,我设法创建了一个 SuggestionBox,它显示(并自动完成)客户的姓名,但在选择时为 bean 设置了一个完整的客户对象(具有多个属性;由 id 标识)。

于 2010-04-28T15:19:42.057 回答
1

<f:parameter<rich:suggestionbox作品中使用标签吗?

于 2009-07-28T23:29:29.537 回答
0

你看过这个 RichFaces 建议框演示了吗?示例下方有链接可以查看源代码。

编辑:

听起来您需要在用户输入建议框之前,您的 bean 中的状态值。我将使用 RichFaces ajax 支持将 state 的值传递给 bean,因此当调用 autocomplete 方法时,用户在页面上选择的状态是填充郊区列表。

于 2009-05-28T12:19:10.653 回答
0

您可以<f:parameter使用rich:suggestionbox. 我的任务是根据列表元素的某些属性过滤列表,有时该属性可能会被忽略。就像,有时我想要一个只有柑橘类水果的列表,有时我想要整个可用水果的列表。

在页面中:

<rich:suggestionbox usingSuggestObjects="true"
        suggestionAction="#{listBuilder.autocompleteFilterFruit('')}" var="ind"
        for="fruitInput" fetchValue="#{fruit.name}" id="suggestion" >
    <f:param name="constrainInd" value="#{basket.isConstrainedToCitrus}" />

    ...

</rich:suggestionbox>

我有一个类 ( Basket) 知道列表是否必须经过特殊过滤,另一个类 ( ListBuilder) 构建列表。

Basket

public Boolean getIsConstrainedToCitrus ()
{
    return new Boolean ( logic that answers "is this basket for citrus only" );
}

在 ListBuilder 中:

public List<Fruit> autocompleteFilterFruit (Object arg)
{
    List<Fruit> rtnList = new ArrayList<Fruit> ();

    String suggestion = (String) arg;

    // get the filter control that the page retrieved from the Basket
    //
    Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext ().getRequestParameterMap();
    boolean isConstrainedToCitrus = "true".equals (params.get ("constrainInd"));

    // allFruit is a pre-initialized list of all the available fruit. use it to populate the return list according 
    // to the filter rules and matches to the auto-complete suggestions
    for (Fruit item : allFruit)
    {
        if ((!isConstrainedToCitrus || item.isCitrus())  &&  item.name.startsWith(suggestion))
        {
            rtnList.add (item);
        }
    }
    return rtnList;
}
于 2016-04-22T19:49:52.787 回答