@specializes 和 @Named Java

发布于 2025-01-16 17:17:01 字数 385 浏览 1 评论 0原文

当您创建新视图时,应使用 @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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情勿念 2025-01-23 17:17:02

这个问题的答案取决于实体最初是如何创建的。如果要扩展管理实体的类,则必须创建单独的视图。这意味着一个命名类是管理实体的类的扩展。

此后,您必须创建一个与所创建的新命名视图相关的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文