【发布时间】:2017-02-22 00:22:35
【问题描述】:
我收到验证错误:值无效错误。我已经确定问题是equals方法。选择的对象作为参数正确传递,但由于某种原因,与之比较的实体是错误的。
<div class="col-sm-8">
<h:selectOneListbox id="${cc.attrs.id}_test" converter="#{cc.attrs.converter}"
size="#{cc.attrs.selector.selectedList.size()+1}" style="height: 150px"
value="#{cc.attrs.selector.removeItem}" styleClass="form-control">
<f:selectItems value="#{cc.attrs.selector.selectedList}" var="test"
itemValue="#{test}"
itemLabel="#{test.displayName}" />
<f:ajax event="change" render="${cc.attrs.id}_jts_panel ${cc.attrs.id}_legend" />
</h:selectOneListbox>
</div>
这里是equals方法:
@Override
public boolean equals(Object object)
{
if (!(object instanceof ObjectTest))
{
return false;
}
ObjectTest other = (ObjectTest) object;
if (this.attribute1 == null || this.attribute2 == null) {
return false;
}
if (other.attribute1 == null || other.attribute2 == null) {
return false;
}
if ((this.attribute1.getName() == null && other.attribute1.getName() != null) || (this.attribute1.getName() != null && !this.attribute1.getName().equals(other.attribute1.getName())))
{
return false;
}
if ((this.attribute2.getName() == null && other.attribute2.getName() != null) || (this.attribute2.getName() != null && !this.attribute2.getName().equals(other.attribute2.getName())))
{
return false;
}
return true;
}
现在由于某种原因,this.attribute1.getName() 与 other.attribute1.getName() 不同。传递给 equals 方法的对象是正确的,但实体本身与传递的对象不同。 this.attribute 的值是如何获取的,因为这是一个 equals 方法所在的实体类?我是不是做错了什么?
【问题讨论】:
-
不太了解您的问题,我猜是您的转换器导致了您的问题:
converter="#{cc.attrs.converter}"这会评估什么? -
你是对的豪尔赫。您可以将您的回复添加为下面的答案,以便我可以接受它作为正确的答案吗?谢谢。
-
完成了。没什么好解释的,只是像你问的那样添加了评论作为答案。很高兴它帮助了你。 :)
标签: validation jsf equals selectonelistbox