I'm trying to implement JSF backing beans using CDI beans as suggested by the depreciation of @ManagedBean and it's scope annotations, but I'm struggling with the right use examples, I'm trying to implement view backing bean with @Model (javax.enterprise.inject.Model) which is @Named @RequestScoped.
I found this question but it's using a ViewScope bean, how would I implement the same functionality with RequestScoped (Preferably @Model), What is best practice use of @Model in general?
Edit 1: I tried creating a new Product in the EditProduct PostConstruct:
@Model
public class EditProduct {
private Product product; // +getter +setter
@Inject
private ProductService productService;
@PostConstruct
public void init(){
product = new Product();
}
public String save() {
productService.save(product);
return "/products?faces-redirect=true";
}
// ...
}
and then setting the product via
<f:viewParameter name="product-id" target="#{editProduct.product}"
converter="#{productConverter}" />
it's working but I'm looking for a best practice.