1 Reply Latest reply on Jul 20, 2007 1:24 PM by ilhami visne

    Object sent to equals() as parameter is null!

    ilhami visne Newbie

      Hello,

      I have an entity bean "CancerType" and a SFSB(long running) "MethSearch" and there is a "search.xhtml".

      One of the search fields in "search.xhtml" is a selectOneMenu, in which all CancerTypes are listed. The selected one is set to "cancerType" variable in MethSearch bean. MethSearch bean has a method "find()", which is called from search.xhtml after a CancerType in selectOneMenu selected.

      Problem: Before Seam the Method "find" calls, the overriden method "equals(Object otherCancerType)" in CancerType Entity is called, but the parameter "otherCancerType" is null. And i need to find why?

      here some codes: first CancerType Entity

      @Entity
      public class CancerType implements java.io.Serializable {
      // id and some string variables
      @Override
       public boolean equals(Object otherCancerType) {
       if(this.id == ((CancerType)otherCancerType).getId())
       return true;
       return this.name.equals(((CancerType)otherCancerType).getName());
       }
      }

      MethSearch SFSB:
      @Stateful
      @Name("methsearch")
      public class MethSearch implements IMethSearch{
       @PersistenceContext(type=PersistenceContextType.EXTENDED)
       private EntityManager entityManager;
      .....
      @Begin
       public void find() {
       Criteria criteria = ....
      }
      


      search.xthml:
      <h:outputLabel for="cancerTypeid">Cancer type:</h:outputLabel>
       <h:selectOneMenu id="cancerTypeid" value="#{methsearch.cancerType}">
       <s:selectItems value="#{cancerTypeDAO.getAll()}" var="cancerType" label="#{cancerType.name}"
       noSelectionLabel="Please Select..."/>
       <s:convertEntity />
       </h:selectOneMenu>
      ....
      <h:commandButton value="Find" action="#{methsearch.find()}" />
      


      and pages.xml:
      <page view-id="/search.xhtml">
       <navigation from-action="#{methsearch.find()}">
       <end-conversation/>
       <redirect/>
       </navigation>
       </page>


      Thank you in advance :)

        • 1. Re: Object sent to equals() as parameter is null!
          ilhami visne Newbie

          I forgot the Stack Trace(a part of it, which i think important to the problem is):

          java.lang.NullPointerException
           at org.arcs.methcancerdb.model.CancerType.equals(CancerType.java:43)
           at javax.faces.component.UISelectOne.matchValue(UISelectOne.java:185)
           at javax.faces.component.UISelectOne.validateValue(UISelectOne.java:137)
           at javax.faces.component.UIInput.validate(UIInput.java:867)
           at javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
           at javax.faces.component.UIInput.processValidators(UIInput.java:666)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
           at javax.faces.component.UIForm.processValidators(UIForm.java:229)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
           at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
           at org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
           at org.ajax4jsf.framework.ajax.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:315)
           at org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:53)
           at org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:191)
           at org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:329)