0
我面臨着與對一個奇怪的問題:自動完成,我獲得以下錯誤PrimeFaces自動完成錯誤
java.lang.NumberFormatException:對於輸入字符串:「玩家」
我的代碼下面
XHTML
<p:autoComplete id="schedChemAC" value="#{testMB.selectedPlayer}" completeMethod="#{testMB.completePlay}" process="@this" var="m" itemLabel="#{m.player}" itemValue="#{m}" converter="#{testConverter}">
<p:ajax event="itemSelect" listener="#{testMB.onSelectFrstL}" process="@this"/>
</p:autoComplete>
的MBean
public List<Player> getSelectedPlayer() {
return selectedPlayer;
}
public void setSelectedPlayer(List<Player> selectedPlayer) {
this.selectedPlayer = selectedPlayer;
}
public void getName() {
playerName = playerSession.getAll();
}
public List<Player> completePlay(String query) {
List<Player> suggestion = new ArrayList<Player>();
if (playerName == null) {
getName();
}
for (Player c : playerName) {
if (c.getPlayer().toUpperCase().contains(query.toUpperCase())) {
suggestion.add(c);
}
}
return suggestion;
}
public void onSelectFrstL(SelectEvent event) {
}
轉換
@Named(value = "testConverter")
public class TestConverter implements Converter {
@EJB
PlayerSession playSession;
public static List<Player> playLst;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (playLst == null) {
playLst = playSession.getAll();
}
if (value.trim().equals("")) {
return null;
} else {
try {
int number = Integer.parseInt(value);
for (Player c : playLst) {
if (c.getPk() == number) {
return c;
}
}
} catch (Exception ex) {
System.out.println("error");
}
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((Player) value).getPk());
}
}
}
我無法找到什麼是錯在上面的代碼,如果我刪除了var,項目值,itemLabel,轉換器部分,那麼它工作正常但是一旦我把var,itemValue,itemLabel,轉換器代碼(如在主要展示中給出的)我得到上述錯誤。 請指導我做什麼,我做錯了什麼,或者我應該檢查什麼。
注:我的示例表只有兩列,pk(int)& player(string)。