问题描述:

I am trying to add a new item using formlayout form to JPAContainer in vaddin 7. I use this code snippet:

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);

}

The main idea is that I want to create a unified vaadin table with editing form that fits for mostly entities (data base tables) in my project. So I pass dao object name as string parameter (don't ask why) and then i lookup it through jndi service. The dao object is tied with entity and extends JPAcontainer<entityClass> class. This approach worked perfectly in Vaadin 6 version with JPAContainer 2.2.0 but after migrating to Vaadin 7 and JPAContainer 3.0.0 eclipse throws me a syntax error in these lines (errors are in comments respectively every line below):

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)

网友答案:

It seems your declaration of the container variable is something like this: JPAContainer<?> container;

So your warnings could be avoided by declaring the container variable like this: JPAContainer<Object> container; Or this: JPAContainer container;

Here you will find some additional information about wildcards in java generics: http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html

相关阅读:
Top