Vaadin 7 createEntityItem和JPAContainer Eclipse的addentity在代码中显示语法错误

时间:2013-07-05 11:53:06

标签: jpa persistence jpa-2.0 vaadin

我正在尝试使用formlayout格式向vaadin 7中的JPAContainer添加一个新项目。我使用此代码段:

String paramDAO = "PersonDAO";        //this parameter can be acquired from url, http request, data file and etc
Class<?> TC = null;      //DAO class

InitialContext ic;
ic = new InitialContext();
TO = ic.lookup("java:app/MyDAOProject/"+paramDao);   
// PersonDAO class extends JPAContainer<PersonEntity>

container =  (JPAContainer<?>) TO;
T = container.getEntityClass();

if(event.getButton() == newButton)
    {               
        final EntityItem newRecord = container.createEntityItem(T.newInstance());        //eclipse shows syntax error here              
        final EditorWindow editor = new EditorWindow(newRecord, T, visibleColumns, this.entytiPropFactory);

        editor.setCaption("New record");
        editor.addListener(new EditorSavedListener()
            {
                @Override
                public void editorSaved(EditorSavedEvent event) 
                    {
                        container.addEntity(newRecord.getEntity());           //eclipse shows syntax error here
                        new Notification("New record created.", null, Notification.Type.TRAY_NOTIFICATION, true).show(Page.getCurrent());
                    }               
            }                   
        );              
        UI.getCurrent().addWindow(editor);
    }

主要思想是我想创建一个统一的vaadin表,其编辑形式适合我项目中的大多数实体(数据库表)。所以我将dao对象名称作为字符串参数传递(不要问为什么)然后我通过jndi服务查找它。 dao对象与实体绑定并扩展JPAcontainer&lt; entityClass &gt;类。这种方法在Vaadin 6版本中与JPAContainer 2.2.0完美配合,但在迁移到Vaadin 7和JPAContainer 3.0.0后,eclipse在这些行中引发了语法错误(错误在下面的每一行的注释中):

final EntityItem newRecord = container.createEntityItem(T.newInstance()); 
//The method createEntityItem(capture#9-of ?) in the type JPAContainer<capture#9-of ?> is not applicable for the arguments (capture#10-of ?)

container.addEntity(newRecord.getEntity());
//The method addEntity(capture#12-of ?) in the type JPAContainer<capture#12-of ?> is not applicable for the arguments (Object)  

1 个答案:

答案 0 :(得分:0)

看来你的容器变量声明是这样的:
JPAContainer<?> container;

因此可以通过声明容器变量来避免警告:
JPAContainer<Object> container;
或者这个:
JPAContainer container;

在这里,您将找到有关java泛型中通配符的一些其他信息: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html