2011-05-03 97 views
2

我对如何使用GWT的ValueListBox和编辑器感到困惑。我得到这个错误:GWT ValueListBox编辑器

The method setValue(String) in the type TakesValueEditor<String> 
is not applicable for the arguments (List<String>) 

这是相关的代码。

public class MyBean { 
    private List<String> dateFormats; 
    public List<String> getDateFormats() { 
     return dateFormats; 
    } 
    public void setDateFormats(List<String> dateFormats) { 
     this.dateFormats = dateFormats; 
    } 
} 

public interface MyBeanView extends IsWidget, Editor<MyBean> { 
    @Path("dateFormats") 
    IsEditor<TakesValueEditor<String>> getDateFormatEditor(); 
} 

public class MyBeanViewImpl implements MyBeanView { 
    @UiField(provided=true) ValueListBox<String> dateFormats; 

    public MyBeanViewImpl() { 
     dateFormats = new ValueListBox<String>(PassthroughRenderer.instance(), 
       new ProvidesKey<String>() { 
        @Override 
        public Object getKey(String item) { 
         return item; 
        } 
     }); 
     dateFormats.setAcceptableValues(Arrays.asList(new String[] {"YYYY"})); 
     // ... binder.createAndBindUi(this); 
    } 

    @Override 
    public IsEditor<TakesValueEditor<String>> getDateFormatEditor() { 
     return dateFormats; 
    } 
} 

这里有什么用的xmlns ui.xml:G = '瓮:进口:com.google.gwt.user.client.ui'>

<g:HTMLPanel> 
    Data Formats: <g:ValueListBox ui:field="dateFormats"> </g:ValueListBox> 
    </g:HTMLPanel> 

我肯定缺少明显的东西这里。非常感谢。

回答

3

您遇到的问题与尝试将List<String> dateFormatsMyBean映射到ValueListBox<String> dateFormats编辑器中有关。数据类型不兼容,因为ValueListBox<T>不编辑List<T>,而是从setAcceptableValues()提供的列表中选择单个实例T。根据上面的示例,MyBean具有String getDateFormat()属性并将编辑器字段重命名为dateFormat是有意义的。

+0

感谢BobV做了一些烦人而又必要的工作,指出后见之明。 – Glenn 2011-05-06 23:17:01

+0

'MyBean'应该只有一个字段'String dateFormat'吗?而编辑器只有一个字段'ValueListBox dateFormat'。它会让我看到更正后的代码..谢谢! – 2018-01-19 08:17:25