'@specializes and @Named Java

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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jaConfu