Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-1581

UISelectOne encounters exception in call to equals()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.5
    • 1.1.6
    • General
    • None
    • Any, found using JDK 1.6, JBoss 4.0.1, Windows XP SP2

    Description

      After doing a bit of research, I'm convinced a problem occurs when SelectItem.itemValue is an EJB. Given that 1.1.3 and the RI (1.2_04) do not have this problem, I suggest the current implementation be changed. If I'm wrong, please help me understand. Otherwise, I'll submit a change request.

      JSP contents:
      <h:selectOneMenu id="client" value="#

      {myPage.projectType}

      " required="true">
      <f:converter converterId="x.y.ProjectTypeConverter"/>
      <f:selectItem itemValue="" itemLabel="--- Select Project Type---"/>
      <f:selectItems value="#

      {myPage.projectTypeList}

      "/>
      </h:selectOneMenu>

      Where ProjectTypeConverter returns null for "" on input and myPage.projectTypeList is a list of SelectItem created in the following manner:

      ArrayList projectTypes = new ArrayList( projectTypeHome.findAll() );
      for( int i = 0; i < projectTypes.size(); i++ )

      { ProjectTypeLocal projectType = (ProjectTypeLocal)projectTypes.get( i ); m_projectTypes.add( new SelectItem( projectType, projectType.getName() ) ); }

      Note that the SelectItem.itemValue is an EJB.

      The intent is to force the user to select a value from the list. If no action is taken by the user, generate an error. This is directly analogous to a Tomahawk example, except the values are EJB's.

      The problem:
      This worked fine under MyFaces 1.1.3 and appears that it would work under RI 1.2_04. Under release 1.1.5, however, a ClassCastException occurs during the validation phase, but only if a list item is selected and the item is an EJB.

      Analysis (based on 1.1.5 release):
      During the validation phase, UISelectOne.validateValue is invoked with the selected EJB. This causes the following lines in _SelectItemsUtil.matchValue() to be invoked:

      [item is class SelectItem]
      Object itemValue = item.getValue();
      if (value==itemValue || value.equals(itemValue))

      This is fine for the SelectItem values that are EJB's, but not for "". Since EJB equality requires identity, the EJB equals() method calls isIdentical() and immediately encounters an exception casting to EJBLocalObject (code here from JBoss 4.0.4GA LocalProxy):

      Boolean isIdentical(final Object a, final Object b)
      {
      final EJBLocalObject ejb = (EJBLocalObject)a;
      Boolean isIdentical = Boolean.FALSE;
      if( ejb != null )

      { isIdentical = new Boolean(ejb.toString().equals(b)); }

      return isIdentical;
      }

      Possible solution:
      In _SelectItemsUtil.matchValue() change the lines above to:

      [item is class SelectItem]
      Object itemValue = item.getValue();
      if (value==itemValue || ( itemValue != null && itemValue.equals(value)))

      Note: The attached test files attempt to recreate the exception with a POJO rather than an EJB.

      Attachments

        1. _SelectItemsUtil.java.diff
          0.5 kB
          Bob
        2. faces-config.xml
          1 kB
          Bob
        3. testValues.jsp
          1 kB
          Bob
        4. MyValue.java
          1 kB
          Bob
        5. TestMyValues.java
          2 kB
          Bob

        Activity

          People

            Unassigned Unassigned
            fastbob Bob
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: