5

RichFaces を使用する場合、テキスト入力を含むページからバッキング BeansuggestionBoxに複数の ID または値を渡す方法を教えてください。suggestionBox例: 選択した州内の提案された都市のリストを表示するには? これが私の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;
}

ご覧のとおり、ページから渡された 1 つの値があり、それは( faceLets 内の)Objectのテキストです。h:inputTextm: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="#{...}">を内側にラップして使用すること<a4j:support event="onselect" ajaxSingle="true">です。onselectこれは、SuggestionBox に対してトリガーされたときに、バッキング Bean の追加の値を設定するために使用できます。

このアプローチにより、顧客の名前を表示 (およびオートコンプリート) する SuggestionBox を作成することができましたが、選択すると、Bean の顧客オブジェクト全体(いくつかのプロパティを持つ; ID で識別) が設定されます。

于 2010-04-28T15:19:42.057 に答える
1

Does using <f:parameter tag inside the <rich:suggestionbox work?

于 2009-07-28T23:29:29.537 に答える
0

このRichFacesのSuggestionBoxのデモはもうご覧になりましたか? 例の下に、ソースを表示するためのリンクがあります。

編集:

ユーザーがSuggestionBoxに入力する前に、Beanの状態の値が必要なようです。RichFaces ajax サポートを使用して state の値を Bean に渡し、オートコンプリート メソッドが呼び出されたときに、ユーザーがページで選択した状態が郊外のリストに入力されるようにします。

于 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リストを特別にフィルター処理する必要があるかどうかを知る1 つのクラス ( ) と、リストを作成する別のクラス ( 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 に答える