h:selectOneListBox Validation Error: Value is not Valid
h:selectOneListBox Validation Error: Value is not Valid
我收到验证错误:值无效错误。我已经确定问题出在 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 方法的对象是正确的,但实体本身与传递的对象不同。由于这是 equals 方法所在的实体 class,因此如何获取 this.attribute 的值?我做错了什么吗?
由于我添加的评论解决了你的问题,你要求添加,这里是:
问题是由您使用的转换器引起的:
converter="#{cc.attrs.converter}"
我收到验证错误:值无效错误。我已经确定问题出在 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 方法的对象是正确的,但实体本身与传递的对象不同。由于这是 equals 方法所在的实体 class,因此如何获取 this.attribute 的值?我做错了什么吗?
由于我添加的评论解决了你的问题,你要求添加,这里是:
问题是由您使用的转换器引起的:
converter="#{cc.attrs.converter}"