How to get access to underlying POJO from GWT Editor class

时光毁灭记忆、已成空白 提交于 2019-12-10 19:27:14

问题


I have a HashMap inside my POJO that I am using the Editor framework in GWT to edit. While I have access to the standard member variables bound through thier getters/setters, I don't know how to access the values inside the HashMap. How do I get access to the underlying POJO that is being edited through my editor that is using the SimpleBeanEditorDriver?

My 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);
     }

My Editor:

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;

So given that I have a list of valid Profile ids from the userManager, how do I go about calling the getProfile method from my POJO from within my Editor?


回答1:


What you need is a 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"



来源:https://stackoverflow.com/questions/10059471/how-to-get-access-to-underlying-pojo-from-gwt-editor-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!