0

I am getting a Validation Error: Value is not valid error. I have identified the problem to be the equals method. The object selected gets passed correctly as an argument, but for some reason, the entity that is compared with is wrong.

<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>

Here is the equals method:

@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;
  }

Now for some reason, this.attribute1.getName() is different than other.attribute1.getName(). The object passed into the equals method is the correct one, but the entity itself is a different one than the object passed. How is the value of this.attribute being picked up since this is an entity class where the equals method is at? Am I doing something wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
p192
  • 518
  • 1
  • 6
  • 19
  • Not much to understand your problem, my guess is that you converter is causing your problem: `converter="#{cc.attrs.converter}"` what does this evaluates to? – Jorge Campos Feb 22 '17 at 00:36
  • You are correct Jorge. Can you add your reply as an answer below so I can accept it as the correct one please? And thank you. – p192 Feb 22 '17 at 02:31
  • Done it. Not much to explain just added the comment as an answer like you asked. Glad that it helped you. :) – Jorge Campos Feb 22 '17 at 02:35

1 Answers1

1

Since the comment I added solved your problem and you ask to add it, here it is:

The problem was caused by the converter you are using:

converter="#{cc.attrs.converter}"
Jorge Campos
  • 22,647
  • 7
  • 56
  • 87