私は IceFaces から PrimeFaces に変更しています (本当は RichFaces に変更したかったのですが、新しいバージョンでバグが発生したため変更しません)、primefaces autoComplete を正しく実装するのが困難です。彼のマニュアルによると、オブジェクトのリストを返すメソッドを実装する必要があるだけで、この場合はコンバーターが必要です。
私が返しているリストは、javax.faces.model.SelectItem のリストです。なぜこれへのコンバーターを作成する必要があるのか 本当に理解できませんが、続けましょう。テスト用に単純なコンバーターを作成しましたが、primefaces はコンバーターを認識せず、ブラウザーに次のエラーを返します。
/resources/components/popups/popupBuscaPessoa.xhtml @35,41 itemLabel="#{pessoa.label}": クラス「java.lang.String」にはプロパティ「label」がありません。
これは私のconversorクラスです(テストするだけです):
public class ConversorSelectItem implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value!=null && value.isEmpty())
return null;
SelectItem selectItem=new SelectItem();
selectItem.setLabel(value);
return selectItem;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
return ((SelectItem)object).getLabel();
}
}
これは私が p:autocomplete: を使用しようとする場所です:
<p:autoComplete value="#{modeloPopupBuscaPessoa.itemSelecionado}"
completeMethod="#{controladorSugestaoPessoa.atualizarSugestoes}"
var="pessoa" itemLabel="#{pessoa.label}" itemValue="#{pessoa.value}"
converter="#{conversorSelectItem}"/>
私は何か間違ったことをしましたか?SelectItem の既定のコンバーターはありませんか? このコンバーターを実装する簡単な方法はありますか?