2013-07-05 35 views
1

我試圖在vaadin 7.我用這個代碼片段添加使用的FormLayout形式JPAContainer新項目語法錯誤:Vaadin 7 createEntityItem和addentity到JPAContainer Eclipse中顯示的代碼

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對象與實體綁定並擴展JPA容器< entityClass> class。這種方法在Vaadin 6版本完美地工作與JPAContainer 2.2.0,但遷移到Vaadin 7和JPAContainer之後3.0.0日食拋出我在這些線路中有語法錯誤(誤差分別爲在下面的評論每行):

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) 

回答

0

看來你的容器變量的聲明是這樣的:
JPAContainer<?> container;

所以,你的警告可能會通過聲明這樣的容器變量來避免:
JPAContainer<Object> container;
或者這樣:
JPAContainer container;

在這裏你會找到有關通配符的一些額外的信息在Java泛型: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html