自动完成工作正常,我的意思是当我写东西时,它会从 db 获取值并自动完成,但是当我选择值时,它显示 selectedParty 为 null。顺便说一下,我将这个转换器与 selectOneMenu 一起使用,它工作正常,我可以很容易地被选中值,但自动完成组件存在问题。
我的观点;
<p:autoComplete id="partySearchAutoId" value="#{myController.selectedParty}"
var="party" itemLabel="#{party.partyName}"
itemValue="#{party}" converter="genericConverter"
forceSelection="true"
completeMethod="#{myController.searchParty}">
<p:ajax event="itemSelect" update="soaInputTextId"/>
</p:autoComplete>
我的控制器;
private Party selectedParty;
public List<Party> searchParty(String query) {
List<Party> partyList = genericService.getByTemplate(new Party(), "partyName", query);
return partyList;
}
public Party getSelectedParty() {
return selectedParty;
}
public void setSelectedParty(Party selectedParty) {
this.selectedParty = selectedParty;
}
这是我的转换器;
@FacesConverter("genericConverter")
public class GenericConverter extends SelectItemsConverter {
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value.toString();
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
return super.getAsObject(context, component, value); //To change body of generated methods, choose Tools | Templates.
}
}