Gwt SimpleBeanEditorDriver是否支持自动装箱?

Gwt SimpleBeanEditorDriver是否支持自动装箱?,gwt,editor,Gwt,Editor,我有一个简单的bean: public class SimpleBean implements Serializable { String stringMe; double autoboxMe; // ... boilerplate ... } 我已经创建了一个视图实现编辑器 public class View extends Component implements Editor<SimpleBean> { @UiField HasVal

我有一个简单的bean:

public class SimpleBean implements Serializable {
    String stringMe;
    double autoboxMe;
    // ... boilerplate ...
}
我已经创建了一个视图实现编辑器

public class View extends Component implements Editor<SimpleBean> {

    @UiField
    HasValue<String> stringMeEditor;
    @UiField
    HasValue<Double> autoboxMeEditor;

    // boilerplate uibinder blabla
}

是的,支持自动装箱,但是您应该非常小心,它实际上是您想要的-如果
autoBoxMeEditor.getValue()
返回
null
,当您调用
driver.flush()
时,将出现
NullPointerException

话虽如此,
HasValue
不是一个编辑器,并且您的“bean”没有getter和setter——这两个事实应该意味着您的编辑器都不应该工作,而只应该是字符串。如果你用真实的代码更新问题,我会稍后再查看


从您的编辑:

这是实际的编辑器。仅当LeafValueEditor就位时,此编辑器才起作用。如果LVE被一个简单的“编辑器”替换,它将不会显示任何值

这就是问题所在,这就是为什么它在没有实际说明您的子编辑器是编辑器的情况下工作的原因:

@Override
public void setValue(PageClip value) {
    displayEditor.asEditor().setValue( value.getDisplay() );
    heightEditor.setValue( value.getHeight() );
    widthEditor.setValue( value.getWidth() );
    xPosEditor.setValue( value.getxPos() );
    yPosEditor.setValue( value.getyPos() );
    idEditor.setValue( value.getId() );
}
您不必编写该方法,但由于a)您没有将编辑器称为
Editor
s,并且b)您将父级设置为LeafValueEditor,因此必须

首先,编辑是什么意思?简而言之,您的类型是“我代表编辑树中的某个叶-不要费心查看我的子项(即字段)以了解如何绑定子编辑器”。如果您实际实现了
编辑器
,则编辑器系统将查看该类,并尝试查找任何编辑器字段

接下来,由于您没有任何编辑器字段,移动到
editor
是没有帮助的!不要将您的字段称为HasValue,而是按它们的实际类型来引用它们。这包括接口LeafValueEditor(还记得上面提到的吗?),因此字符串和double将正确绑定



由于您没有共享驱动程序设置的代码,因此将来可能会遇到一个问题:确保在驱动程序声明中引用编辑器实现,而不是在视图界面中引用编辑器实现。您必须这样做,以便驱动程序知道它正在与哪个impl对话,以及哪些子字段(以及类似的子编辑器)预计会有。

您是否尝试设置@Path(“autoboxMe”)到autoboxMeEditor?因为您的bean和视图的字段名称不相同。编辑器框架支持查找具有属性和属性编辑器名称的小部件。并且字符串值设置正确,因此这不是原因。但是,是的:我也尝试了@Path set-无差异。我将getter和setter放在一边,以保持问题很简单,我的代码有所有的getter和setter。但是HasValue不是一个编辑器。让我思考一下:如果ui.xml将一个文本框作为真实字段,这是否有意义?以及:它为什么与HasValue一起工作?@thst,
HasValue
本身不是一个编辑器,因此不会工作。你一定是在某个地方将其称为真正的editor,或者自己调用setValue。如果HasValue确实起作用,并且编辑器框架不理解double->double,您将得到一个错误,即子编辑器与bean中的属性不匹配。关于驱动程序中的接口:我已经发现了困难的方法:-),当然,如果您仔细考虑,这是有意义的。我将尝试替换它与编辑器的接口键入并查看发生了什么。该死。你说得太对了,你不会相信我研究这件事多久了:-/
package de.srs.pen.portal.widgets.metadataeditor;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Widget;

import de.srs.pen.api.meta.xml.PageClip;
import de.srs.pen.portal.widgets.editors.EditorDeleteEvent;
import de.srs.pen.portal.widgets.editors.EditorDeleteEventHandler;

public class PageClipEditorView
        extends Composite
        implements PageClipEditor.View
{

    private static PageClipEditorViewUiBinder uiBinder = GWT.create( PageClipEditorViewUiBinder.class );

    interface PageClipEditorViewUiBinder
            extends UiBinder<Widget, PageClipEditorView>
    {}

    private PageClipEditor activity;

    @UiField
    HasClickHandlers btnDelete;

    @UiField
    @Path("id")
    HasValue<String> idEditor;
    @UiField
    @Path("display")
    PageDisplayEnumEditor displayEditor;
    @UiField
    @Path("xPos")
    HasValue<Double> xPosEditor;
    @UiField
    @Path("yPos")
    HasValue<Double> yPosEditor;
    @UiField
    @Path("height")
    HasValue<Double> heightEditor;
    @UiField
    @Path("width")
    HasValue<Double> widthEditor;

    public PageClipEditorView() {
        initWidget( uiBinder.createAndBindUi( this ) );
    }

    @Override
    public void setActivity(PageClipEditor activity) {
        this.activity = activity;
    }

    @Override
    public PageClipEditor getActivity() {
        return this.activity;
    }

    @Override
    public HandlerRegistration addDeleteHandler(EditorDeleteEventHandler handler) {
        return addHandler( handler, EditorDeleteEvent.TYPE );
    }

    @UiHandler("btnDelete")
    public void handleDelete(ClickEvent ev) {
        fireEvent( new EditorDeleteEvent() );
    }

    @Override
    public void setValue(PageClip value) {
        displayEditor.asEditor().setValue( value.getDisplay() );
        heightEditor.setValue( value.getHeight() );
        widthEditor.setValue( value.getWidth() );
        xPosEditor.setValue( value.getxPos() );
        yPosEditor.setValue( value.getyPos() );
        idEditor.setValue( value.getId() );
    }

    @Override
    public PageClip getValue() {
        PageClip clip = new PageClip( idEditor.getValue(),
                                      xPosEditor.getValue(), yPosEditor.getValue(),
                                      widthEditor.getValue(), heightEditor.getValue(),
                                      displayEditor.asEditor().getValue() );
        return clip;
    }
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:p="urn:import:de.srs.pen.portal.widgets.metadataeditor">
    <ui:with type="de.srs.pen.portal.widgets.metadataeditor.MetadataEditorText"
        field="res" />
    <ui:with type="de.srs.pen.portal.widgets.icons.WidgetIcons"
        field="icon" />

    <ui:style>

    </ui:style>
    <g:HTMLPanel>
        <g:Image ui:field="btnDelete" resource="{icon.circleCloseDeleteGlyph}"
            height="16px" width="16px" title="{res.pageclipDelete}" />
        <g:InlineLabel text="{res.pageclipName}" />
        <g:TextBox ui:field="idEditor" width="5em"/>
        <g:InlineLabel text="{res.pageclipDisplay}" />
        <p:PageDisplayEnumEditor ui:field="displayEditor" />
        <g:InlineLabel text="{res.pageclipXPos}" />
        <g:DoubleBox ui:field="xPosEditor" width="2.5em" />
        <g:InlineLabel text="{res.pageclipYPos}" />
        <g:DoubleBox ui:field="yPosEditor" width="2.5em" />
        <g:InlineLabel text="{res.pageclipHeight}" />
        <g:DoubleBox ui:field="heightEditor" width="2.5em" />
        <g:InlineLabel text="{res.pageclipWidth}" />
        <g:DoubleBox ui:field="widthEditor" width="2.5em" />
    </g:HTMLPanel>
</ui:UiBinder> 
package de.srs.pen.api.meta.xml;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "clip", namespace = "urn:srs.pdx.metadata")
public class PageClip implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 5556156665068106790L;

    @XmlAttribute(required=true)
    protected String id;

    @XmlAttribute(name = "xPos", required = true)
    protected double xPos;

    @XmlAttribute(name = "yPos", required = true)
    protected double yPos;

    @XmlAttribute(name = "width", required = true)
    protected double width;

    @XmlAttribute(name = "height", required = true)
    protected double height;

    @XmlAttribute(name ="display", required = false)
    protected String display;

    public PageClip() {
    }

    public PageClip( String id, double xPos, double yPos, double width, double height ) {
        super();
        this.id = id;
        this.xPos = xPos;
        this.yPos = yPos;
        this.width = width;
        this.height = height;
    }

    public PageClip( String id, double xPos, double yPos, double width, double height, String display ) {
        this(id, xPos, yPos, width, height);
        this.display = display;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getxPos() {
        return xPos;
    }

    public void setxPos(double xPos) {
        this.xPos = xPos;
    }

    public double getyPos() {
        return yPos;
    }

    public void setyPos(double yPos) {
        this.yPos = yPos;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public String getDisplay() {
        return display;
    }

    public void setDisplay(String display) {
        this.display = display;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append( "PageClip [id=" )
            .append( id )
            .append( ", xPos=" )
            .append( xPos )
            .append( ", yPos=" )
            .append( yPos )
            .append( ", width=" )
            .append( width )
            .append( ", height=" )
            .append( height )
            .append( ", display=" )
            .append( display )
            .append( "]" );
        return builder.toString();
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((display == null) ? 0 : display.hashCode());
        long temp;
        temp = Double.doubleToLongBits( height );
        result = prime * result + (int)(temp ^ (temp >>> 32));
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        temp = Double.doubleToLongBits( width );
        result = prime * result + (int)(temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits( xPos );
        result = prime * result + (int)(temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits( yPos );
        result = prime * result + (int)(temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if( this == obj ) {
            return true;
        }
        if( obj == null ) {
            return false;
        }
        if( !(obj instanceof PageClip) ) {
            return false;
        }
        PageClip other = (PageClip)obj;
        if( display == null ) {
            if( other.display != null ) {
                return false;
            }
        }
        else if( !display.equals( other.display ) ) {
            return false;
        }
        if( Double.doubleToLongBits( height ) != Double.doubleToLongBits( other.height ) ) {
            return false;
        }
        if( id == null ) {
            if( other.id != null ) {
                return false;
            }
        }
        else if( !id.equals( other.id ) ) {
            return false;
        }
        if( Double.doubleToLongBits( width ) != Double.doubleToLongBits( other.width ) ) {
            return false;
        }
        if( Double.doubleToLongBits( xPos ) != Double.doubleToLongBits( other.xPos ) ) {
            return false;
        }
        if( Double.doubleToLongBits( yPos ) != Double.doubleToLongBits( other.yPos ) ) {
            return false;
        }
        return true;
    }


}
@Override
public void setValue(PageClip value) {
    displayEditor.asEditor().setValue( value.getDisplay() );
    heightEditor.setValue( value.getHeight() );
    widthEditor.setValue( value.getWidth() );
    xPosEditor.setValue( value.getxPos() );
    yPosEditor.setValue( value.getyPos() );
    idEditor.setValue( value.getId() );
}