Uploaded image for project: 'Errai'
  1. Errai
  2. ERRAI-1029

Binding for Java Enums does not work

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0.0.CR1
    • Fix Version/s: None
    • Component/s: ErraiDataBinding
    • Labels:
      None
    • Steps to Reproduce:
      Hide
      1. Declare some bindable field in template whose value type is some enum:

            @DataField
            @Bound
            @Inject
            protected SingleSelectionButtonGroup<EntryType> entryType;
        

      2. try to bind some non-null value of given enum
        ER: the value is bound and shown on UI
        AR: java.lang.RuntimeException: Converter widget type, com.foo.SomeEnum, does not match the required type, com.foo.SomeEnum$2
      Show
      Declare some bindable field in template whose value type is some enum: @DataField @Bound @Inject protected SingleSelectionButtonGroup<EntryType> entryType; try to bind some non-null value of given enum ER: the value is bound and shown on UI AR: java.lang.RuntimeException: Converter widget type, com.foo.SomeEnum, does not match the required type, com.foo.SomeEnum$2
    • Workaround Description:
      Hide

      Change method org.jboss.errai.databinding.client.BindableProxyAgent.validateTypes(String, Class<?>, Class<?>, String):

      private void validateTypes(final String property, final Class<?> actualType, final Class<?> converterType, final String modelOrWidget) {
          boolean enumCase = converterType.isEnum() && actualType.getSuperclass().equals(converterType);
          if (!enumCase && !actualType.equals(converterType) && !oneTypeIsInterface(actualType, converterType)) {
            throw new RuntimeException("Converter " + modelOrWidget + " type, " + converterType.getName()
                    + ", does not match the required type, " + actualType.getName());
          }
        }
      

      The solution tested and works.

      Show
      Change method org.jboss.errai.databinding.client.BindableProxyAgent.validateTypes(String, Class<?>, Class<?>, String): private void validateTypes( final String property, final Class<?> actualType, final Class<?> converterType, final String modelOrWidget) { boolean enumCase = converterType.isEnum() && actualType.getSuperclass().equals(converterType); if (!enumCase && !actualType.equals(converterType) && !oneTypeIsInterface(actualType, converterType)) { throw new RuntimeException( "Converter " + modelOrWidget + " type, " + converterType.getName() + ", does not match the required type, " + actualType.getName()); } } The solution tested and works.

      Description

      java.lang.RuntimeException: Converter widget type, com.foo.SomeEnum, does not match the required type, com.foo.SomeEnum$2

      The problem lies in BindableProxyAgent.java:394:
      if (!actualType.equals(converterType) && !oneTypeIsInterface(actualType, converterType))

      { throw new RuntimeException("Converter " + modelOrWidget + " type, " + converterType.getName() + ", does not match the required type, " + actualType.getName()); }

      For enums this is not correct comparison: !actualType.equals(converterType)
      So any enum value's class is not equal to the enum's class.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mbarkley Max Barkley
                Reporter:
                klimskiy Ivan Klimskiy
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: