@specializes 和 @Named Java
当您创建新视图时,应使用 @Named 注释。但是,如果视图应该是已经存在的类的扩展,那么应该如何实现。要覆盖类中的方法,我使用以下命令:
@ViewScoped
@Specializes
public class classB extends class A{
@Override
public String save(){
}
}
这允许我保留已经生成的实体。
但视图需要有以下注释:
@Named
@ViewScoped
@URLMapping()
public class classB extends class A{
//content
}
这应该如何在一个类中实现?鉴于这两个注释不能共存?
When you are creating a new view the @Named annotation should be used. However, if the view should be an extension of a class that already exists, how should this be achieved. To overwrite a method in the class I use the following:
@ViewScoped
@Specializes
public class classB extends class A{
@Override
public String save(){
}
}
This allows me to keep the already generated entity.
But the view needs to have the following annotations:
@Named
@ViewScoped
@URLMapping()
public class classB extends class A{
//content
}
How should this be achieved in one class? Given the two annotations cannot coexist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题的答案取决于实体最初是如何创建的。如果要扩展管理实体的类,则必须创建单独的视图。这意味着一个命名类是管理实体的类的扩展。
此后,您必须创建一个与所创建的新命名视图相关的 JSF 页面。
如果存在信息传输,则必须使用专门注释创建适当的扩展类才能访问实体。
如果您尝试操作新视图类中的实体,您将导致合并错误,因为程序已经认为该实体存在于数据库中。
The answer to this question depends on how the entity was originally created. If you are extending a class that manages an entity, you must create a separate view. That means one named class that is an extension of the class managing the entity.
After this, you must create a correlating JSF page to that new named view that was created.
If there is a transfer of information, you must create a proper extended class with the specializes annotation to have access to the entity.
If you attempt to manipulate the entity in the new view class you will cause a merge error because the program already thinks the entity exists in the database.