2011-02-13 3 views
2
여기

문제입니다 : 나는 콩이 콩이 열거 속성이 있습니다GWT, 열거 경우 RadioButton 및 편집자 워크

enum E { 
    ONE, TWO, THREE; 
} 

class A implements Serializable { 
    public E foo; 
} 

I 사용자 편집이 빈을 수 있도록 GWT Editor framework을 사용하고 싶습니다

[ERROR] [gwtmodule] - Could not find a getter for path one in proxy type com.company.A

[ERROR] [gwtmodule] - Could not find a getter for path two in proxy type com.company.A

[ERROR] [gwtmodule] - Could not find a getter for path three in proxy type com.company.A

GWT 2.2에서이 작품을 만들 수있는 방법이 있나요 :

public class P extends FlowPanel implements Editor<A> { 
    // ... UiBinder code here ... 
    @UiField RadioButton one, two, three; 
    // ... 
} 

나는 오류가있어?

답변

8
public class EnumEditor extends FlowPanel implements LeafValueEditor<E> { 

    private Map<RadioButton, E> map; 

    @UiConstructor 
    public EnumEditor(String groupName) { 
     map = new HashMap<RadioButton, E>(); 
     for (E e: E.class.getEnumConstants()){ 
      RadioButton rb = new RadioButton(groupName, e.name()); 
      map.put(rb, e); 
      super.add(rb); 
     } 
    } 

    @Override 
    public void setValue(E value) { 
     if (value==null) 
      return; 
     RadioButton rb = (RadioButton) super.getWidget(value.ordinal()); 
     rb.setValue(true); 
    } 

    @Override 
    public E getValue() { 
     for (Entry<RadioButton, E> e: map.entrySet()) { 
      if (e.getKey().getValue()) 
       return e.getValue(); 
     } 
     return null; 
    } 
} 
+2

감사가있다. – Stevko

1

문제는 열거 형과 관련이 없습니다. 컴파일러는 uiFields one, two 및 three에 해당하는 bean과 유사한 getter 메소드를 찾고 있습니다. RadioButtons는 IsEditor<LeafValueEditor<java.lang.Boolean>> 인터페이스를 구현할 때 부울 속성에 매핑됩니다. 당신이 좋겠

class A implements Serializable { 
    public E foo; 
    public Boolean getOne() {return foo==E.ONE;} 
    public Boolean getTwo() {return foo==E.TWO;} 
    public Boolean getThree() {return foo==E.THREE;} 
} 

는 하나의 열거 속성 (및 해당 게터/세터)에 라디오 버튼의 그룹을 매핑하려면 다음

이 당신의 예제 코드가 작동해야하지만, 분명히 매우 유연한 솔루션이 아니다 라디오 버튼 그룹을 감싸는 자신 만의 편집기를 구현하고 E 타입의 값을 반환해야합니다. IsEditor<LeafValueEditor<E>>과 같은 인터페이스를 구현해야합니다.

이 코드 안토니오를 올리기위한 related discussion on the GWT group