2011-02-13 10 views
2

ここでは問題です:私は豆と、このBeanを持つ列挙型プロパティを持っている:GWT、列挙型、ラジオボタンとエディタフレームワーク

enum E { 
    ONE, TWO, THREE; 
} 

class A implements Serializable { 
    public E foo; 
} 

私はこのBean

ユーザーの編集をできるように GWT Editor frameworkを使用したいです
public class P extends FlowPanel implements Editor<A> { 
    // ... UiBinder code here ... 
    @UiField RadioButton one, two, three; 
    // ... 
} 

私はエラーを持っている:

[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でこの作品を作るための方法はありますか?

答えて

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

問題は列挙型ではありません。コンパイラは、1、2、3のuiFieldsに対応するBeanのようなゲッターメソッドを探しています。 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

関連する問題