我有我的自动完成组件连接到我的托管 bean,然后连接到我的服务层并从数据库中获取列表。我正在尝试参考展示和我在网上找到的任何其他内容,但我无法让我的自动完成功能正常工作。我有一个演员异常,所以看起来我需要一个转换器。但是我在编写转换器时遇到了麻烦。我对一切是如何传递的感到困惑。
<p:autoComplete id="placesSearchBar" value="#{searchBarBean.place}" completeMethod="#{searchBarBean.findSimilarPlaces}"
var="Place" itemLabel="#{Place.name}" itemValue="#{Place}" converter="PlaceConverter" />
public class SearchBarBean
{
private Place place;
private SearchQueryService searchQueryService;
private Criteria criteria;
/**
* @return the place
*/
public Place getPlace() {
return place;
}
/**
* @param place the place to set
*/
public void setPlace(Place place) {
this.place = place;
}
/**
* @return the searchQueryService
*/
public SearchQueryService getSearchQueryService() {
return searchQueryService;
}
/**
* @param searchQueryService the searchQueryService to set
*/
public void setSearchQueryService(SearchQueryService searchQueryService) {
this.searchQueryService = searchQueryService;
}
/**
* @return the criteria
*/
public Criteria getCriteria() {
return criteria;
}
/**
* @param criteria the criteria to set
*/
public void setCriteria(Criteria criteria) {
this.criteria = criteria;
}
public List<Place> findSimilarPlaces(String query)
{
getCriteria().setName(query);
List<Place> places = getSearchQueryService().findPlaces(criteria);
return places;
}
}
public class PlaceConverter implements Converter
{
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String submittedValue) {
SearchBarBean searchBarBean = new SearchBarBean();
return null;
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
return null;
}
}