title: Famous Validation Error: Value is not valid
body: <p>I searched for this famous "Validation Error: Value is not valid" a lot. I know it may be related to equals method. But couldn't find what is wrong with mine. </p>
  
  <p>xhtml: </p>
  
  <pre><code>&lt;h:selectOneMenu id="ayarMenuSA" rendered="#{teklifIslemleriBean.selectedITip == 1}" converter="metalConverter" value="#{teklifIslemleriBean.satisTeklif.metal}"&gt;
        &lt;f:selectItems value="#{teklifIslemleriBean.ayarMenu}" /&gt;
  &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>backing bean:</p>
  
  <pre><code>List&lt;Metal&gt; metalList = teklifIslemServisi.metalKodunaGoreMetalGetir(null, selectedMK);           
  ayarMenu.clear();
  for (Metal m : metalList) {
      ayarMenu.add(new SelectItem(m, "Stok No:" + m.getMetalNo() + " ,Ayar: " + m.getAyar() + " ,Ağırlık: " + m.getAgirlik() + " ,MetalKod: " + m.getMetalKod().getMetalKodu()));
  }
  </code></pre>
  
  <p>pojo:</p>
  
  <pre><code>public class Metal implements java.io.Serializable {
  
      private Integer metalNo;
      private MetalTip metalTip;
      private MetalKod metalKod;
      private BigDecimal agirlik;
      private BigDecimal ayar;
      private boolean durum;
  
      public Metal() {
      }
  
      public Metal(boolean durum) {
          this.durum = durum;
      }
  
      public Metal(MetalTip metalTip, MetalKod metalKod, BigDecimal agirlik, BigDecimal ayar, boolean durum) {
          this.metalTip = metalTip;
          this.metalKod = metalKod;
          this.agirlik = agirlik;
          this.ayar = ayar;
          this.durum = durum;
      }
  
  
      public Integer getMetalNo() {
          return this.metalNo;
      }
  
      public void setMetalNo(Integer metalNo) {
          this.metalNo = metalNo;
      }
  
      public MetalTip getMetalTip() {
          return this.metalTip;
      }
  
      public void setMetalTip(MetalTip metalTip) {
          this.metalTip = metalTip;
      }
  
      public MetalKod getMetalKod() {
          return this.metalKod;
      }
  
      public void setMetalKod(MetalKod metalKod) {
          this.metalKod = metalKod;
      }
  
      public BigDecimal getAgirlik() {
          return this.agirlik;
      }
  
      public void setAgirlik(BigDecimal agirlik) {
          this.agirlik = agirlik;
      }
  
      public BigDecimal getAyar() {
          return this.ayar;
      }
  
      public void setAyar(BigDecimal ayar) {
          this.ayar = ayar;
      }
  
      public boolean isDurum() {
          return this.durum;
      }
  
      public void setDurum(boolean durum) {
          this.durum = durum;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          final Metal other = (Metal) obj;
          if (this.metalNo != other.metalNo &amp;&amp; (this.metalNo == null || !this.metalNo.equals(other.metalNo))) {
              return false;
          }
          if (this.metalTip.getMetalTipiId() != other.metalTip.getMetalTipiId() &amp;&amp; (this.metalTip == null || this.metalTip.getMetalTipiId() != (other.metalTip.getMetalTipiId()))) {
              return false;
          }
          if (!this.metalKod.getMetalKodu().equals(other.metalKod.getMetalKodu()) &amp;&amp; (this.metalKod == null || !this.metalKod.getMetalKodu().equals(other.metalKod.getMetalKodu()))) {
              return false;
          }
          if (this.agirlik != other.agirlik &amp;&amp; (this.agirlik == null || !this.agirlik.equals(other.agirlik))) {
              return false;
          }
          if (this.ayar != other.ayar &amp;&amp; (this.ayar == null || !this.ayar.equals(other.ayar))) {
              return false;
          }
          return true;
      }
  
      @Override
      public int hashCode() {
          int hash = 3;
          hash = 17 * hash + (this.metalNo != null ? this.metalNo.hashCode() : 0);
          hash = 17 * hash + (this.metalTip != null ? this.metalTip.hashCode() : 0);
          hash = 17 * hash + (this.metalKod != null ? this.metalKod.hashCode() : 0);
          hash = 17 * hash + (this.agirlik != null ? this.agirlik.hashCode() : 0);
          hash = 17 * hash + (this.ayar != null ? this.ayar.hashCode() : 0);
          return hash;
      }
  
  
  
  }
  </code></pre>
  
  <p>converter:</p>
  
  <pre><code>@FacesConverter("metalConverter")
  public class MetalConverter implements Converter, Serializable {
  
      private static final long serialVersionUID = -1L;
  
  
      @Override
      public Object getAsObject(FacesContext facesContext, UIComponent component, String str) {
          if (str == null || str.length() == 0) {
              return null;
          }
          System.out.println("metalConverter getAsObject("+ str);
          Metal metal = new Metal();
          String values[] = str.split(":");
  
          if (values.length &gt; 1) {
              metal.setMetalNo(Integer.parseInt(values[0]));
              metal.setAyar(new BigDecimal(values[1]));
              metal.setAgirlik(new BigDecimal(values[2]));//?? intcompact=1500
              metal.setMetalKod(new MetalKod(values[3]));
              metal.setMetalTip(new MetalTip(values[4]));
          }
          return metal;
      }
  
      Integer getKey(String value) {
          Integer key;
          key = Integer.valueOf(value);
          return key;
      }
  
      String appendString(Integer value) {
          StringBuilder sb = new StringBuilder();
          sb.append(value);
          return sb.toString();
      }
  
      @Override
          public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
  
              if (object == null) {
                  return null;
              }
              if (object instanceof Metal) {
                  Metal metal = (Metal) object;
                  StringBuilder sb = new StringBuilder();
                  sb.append(metal.getMetalNo());
                  sb.append(':');
                  sb.append(metal.getAyar().toString());
                  sb.append(':');
                  sb.append(metal.getAgirlik().toString());
                  sb.append(':');
                  sb.append(metal.getMetalKod().getMetalKodu());
                  sb.append(':');
                  sb.append(metal.getMetalTip().getMetalTipiId());
                  System.out.println("metalConverter getAsString(object) -&gt; " + sb.toString());
                  return sb.toString();
  
              } else {
                  throw new IllegalArgumentException(object + " nesnesi " + object.getClass().getName() + "tipinde geliyor; olması gereken tip ise: " + Metal.class.getName());
              }
          }
  </code></pre>
  
  <p>Actually if I write equals method this way:</p>
  
  <pre><code> @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          final Metal other = (Metal) obj;
          return true;
      }
  </code></pre>
  
  <p>it works fine. But for some reasons I have to use the above code. Does anyone have any idea about this issue?</p>