我正在尝试使用 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< entityClass > 类。这种方法在带有 JPAContainer 2.2.0 的 Vaadin 6 版本中完美运行,但是在迁移到 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)