我有一个ap:selectOneMenu的问题,无论我做什么我都无法让JSF调用JPA实体上的setter.JSF验证失败,显示以下消息:
form:location:验证错误:值无效
我有这个工作在几个相同类型的其他类(即,连接表类),但不能为我的生活让这一个工作.
如果有人可以针对此类问题提出一些故障排除/调试技巧,我们将不胜感激.
使用日志语句我已经验证了以下内容:
Conveter将返回正确的,非null数值.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>
Run Code Online (Sandbox Code Playgroud)
转换器:
@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, …Run Code Online (Sandbox Code Playgroud) 我的JSF页面
<h:form>
<h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
<p:ajax event="change" process="studlist" update="studdep" ></p:ajax>
<f:selectItems value="#{studBean.student}" var="s"
itemValue="#{s.studid}" itemLabel="#{s.name}"/>
<f:converter converterId="studentconverter"/>
</h:selectOneMenu>
</h:form>
Run Code Online (Sandbox Code Playgroud)
转换器类(StudentConverter)
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Student studConvert= new Student();
List<Student> students=new ArrayList<Student>();
students=(ArrayList<Student>)((UISelectItems
component.getChildren().get(0)).getValue();
}
Run Code Online (Sandbox Code Playgroud)
在这个转换器上,Argument'String value'给itemLabel我为什么会这样?我在这个字符串上使用itemValue