h:selectOneListBox验证错误:值无效

时间:2017-02-22 00:22:36

标签: validation jsf equals selectonelistbox

我收到验证错误:值无效错误。我已经确定问题是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方法的实体类?我做错了吗?

1 个答案:

答案 0 :(得分:1)

由于我添加的评论解决了您的问题并且您要求添加它,这里是:

问题是由您使用的转换器引起的:

converter="#{cc.attrs.converter}"