如何从GWT编辑器类访问底层的POJO [英] How to get access to underlying POJO from GWT Editor class
问题描述
我在POJO中有一个HashMap,我正在使用GWT中的Editor框架进行编辑。虽然我可以访问通过getter / setter绑定的标准成员变量,但我不知道如何访问HashMap中的值。我如何访问正在使用SimpleBeanEditorDriver编辑器编辑的底层POJO?
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?
我的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;
假设我有一个userManager中有效的Profile ID列表,我该如何去调用在我的编辑器中从我的POJO获得getProfile方法?
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?
推荐答案
您需要的是 ValueAwareEditor
。
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
或者,如果您想要更多挑战,可以查看自己的 CompositeEditor
,例如查看 ListEditor
的源代码。在你的情况下,你可以实现 CompositeEditor< ProfileConfig,ProfileInfo,MyNewProfileInfoEditor>
。你可以这样做为:这个编辑器会带一个 ProfileConfig
对象,提取一个或多个 ProfileInfo
对象并编辑它与一个或多个 MyNewProfileInfoEditor
编辑器
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"
这篇关于如何从GWT编辑器类访问底层的POJO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!