验证错误:值无效
我有一个ap:selectOneMenu的问题,无论我做什么我都无法让JSF调用JPA实体上的setter。JSF验证失败,显示以下消息:
form:location:验证错误:值无效
我有这个工作在几个相同类型的其他类(即,连接表类),但不能为我的生活让这一个工作。
如果有人可以针对此类问题提出一些故障排除/调试技巧,我们将不胜感激。
使用日志语句我已经验证了以下内容:
在Conveter将返回正确的,非null数值。
我的JPA实体中没有Bean验证。
setLocation(Location location)永远不会调用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>转换器:
@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 method
INFO: Current value=ejb.locations.Location[id=null, name=null, latitude=0.0, longitude=0.0]
// Session Bean
INFO: Finding ejb.locations.Location with id=3
牧羊人nacy
明月笑刀无情
随时随地看视频慕课网APP
相关分类