3

我的 POJO 中有一个 HashMap,我正在使用 GWT 中的编辑器框架进行编辑。虽然我可以访问通过他们的 getter/setter 绑定的标准成员变量,但我不知道如何访问 HashMap 中的值。如何访问正在通过使用 SimpleBeanEditorDriver 的编辑器编辑的底层 POJO?

我的 POJO:

@Entity(noClassnameStored=true)
public class ProfileConfig extends BaseEntity {
     @Indexed(unique=true)
     private String name;
     private boolean isDefault;
     private HashMap<ProfileID, ProfileInfo> profiles= new HashMap<ProfileID, ProfileInfo>();

     public ProfileInfo getProfile(ProfileID id) {
          return profiles.get(id);
     }

     public void setProfile(ProfileID id, ProfileInfo p) {
         profiles.put(id, p);
     }

我的编辑器:

public class ProfileConfigEditor extends Composite implements ManagedObjectEditor<ProfileConfig> {

     private static ProfileConfigEditorUiBinder uiBinder = GWT.create(ProfileConfigEditorUiBinder.class);
     interface ProfileConfigEditorUiBinder extends UiBinder<Widget, ProfileConfigEditor> {
}

     private UserManager userManager;

     @UiField
     CellList Profiles;
     @UiField
     TextBox name;
     @UiField
     CheckBox isDefault;

因此,鉴于我有一个来自 userManager 的有效配置文件 ID 列表,我该如何从我的编辑器中的 POJO 调用 getProfile 方法?

4

1 回答 1

2

你需要的是一个ValueAwareEditor.

public class ProfileConfigEditor extends Composite implements ManagedObjectEditor<ProfileConfig>, ValueAwareEditor<ProfileConfig> {

void setValue(ProfileConfig value){
    // TODO: Call ProfileConfig.getProfile()
}

void flush(){
   // TODO: Call ProfileConfig.setProfile()
}


// ... Other methods here

Alternatively, if you want more of a challenge, you can look at rolling your own CompositeEditor, for example see the source code for ListEditor. In your case, you would implement a CompositeEditor<ProfileConfig, ProfileInfo, MyNewProfileInfoEditor>. You can this of this as "This editor will take a ProfileConfig object, extract one or more ProfileInfo objects and edit it with one or more MyNewProfileInfoEditor editors"

于 2012-04-13T21:45:57.127 回答