驗證錯誤:值無效我有一個ap:selectOneMenu的問題,無論我做什么我都無法讓JSF調(diào)用JPA實體上的setter。JSF驗證失敗,顯示以下消息:form:location:驗證錯誤:值無效我有這個工作在幾個相同類型的其他類(即,連接表類),但不能為我的生活讓這一個工作。如果有人可以針對此類問題提出一些故障排除/調(diào)試技巧,我們將不勝感激。使用日志語句我已經(jīng)驗證了以下內(nèi)容:在Conveter將返回正確的,非null數(shù)值。我的JPA實體中沒有Bean驗證。setLocation(Location location)永遠不會調(diào)用setter 。這是我能做的最簡單的例子,它根本不起作用:<h:body>
<h:form id="form">
<p:messages id="messages" autoUpdate="true" />
<p:selectOneMenu id="location" value="#{locationStockList.selected.location}" converter="locationConverter">
<p:ajax event="change" update=":form:lblLocation"/>
<f:selectItems value="#{locationStockList.locationSelection}"/>
</p:selectOneMenu>
</h:form></h:body>轉(zhuǎn)換器:@FacesConverter(forClass=Location.class, value="locationConverter")public class LocationConverter implements Converter, Serializable {
private static final Logger logger = Logger.getLogger(LocationConverter.class.getName());
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value.isEmpty())
return null;
try {
Long id = Long.parseLong(value);
Location location = ((LocationManagedBean) context.getApplication().getELResolver().getValue(context.getELContext(), null,
"location")).find(id);
logger.log(Level.SEVERE, "Converted {0} to {1}" , new Object[] {value, location});
return location;
} catch (NumberFormatException e) {
return new Location();
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null || value.toString().isEmpty() || !(value instanceof Location))
return "";
return String.valueOf(((Location) value).getId());
} }控制臺輸出:// Getter methodINFO: Current value=ejb.locations.Location[id=null, name=null, latitude=0.0, longitude=0.0] // Session BeanINFO: Finding ejb.locations.Location with id=3
驗證錯誤:值無效
牧羊人nacy
2019-05-27 11:16:10