使用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中)
required="true" maxlength="100" size="30" />
Box height="200" width="200" usingSuggestObjects="true"
suggestionAction="#{suburbsMBean.autocomplete}" var="suburb" for="suburb"
fetchValue="#{suburb.name}" id="suggestion">
Box>
最佳答案
(免责声明:我知道这个问题很久以前就被问过了,但也许这会帮助有类似问题的人…)
查看此博客文章,其中涉及类似的内容:RichFaces – SuggestionBox and hidden field.
关键是使用< f:setPropertyActionListener value =“#{...}”target =“#{...}”>包裹在里面< a4j:support event =“onselect”ajaxSingle =“true”>.当为SuggestionBox触发onselect时,这可用于为辅助bean设置附加值.
通过这种方法,我设法创建一个SuggestionBox,显示(和自动填充)客户的名称,但在选择时为bean设置一个完整的客户对象(具有几个属性;由id标识).