In MVC
, as I know, the Model
is the part related to data and database, it is basically related to data that is added, modified, displayed and so on...
To make sure of this I extract the following from Wikipedia:
A model stores data that is retrieved according to commands from the controller and displayed in the view.
And this from Chrome Developers:
Model is where the application’s data objects are stored. The model doesn’t know anything about views and controllers. When a model changes, typically it will notify its observers that a change has occurred.
So I was reading a little bit about CDI and I saw the @Model
annotation (@Named + @RequestScoped)
that is available under the package javax.enterprise.inject
with the following description:
/**
* <p>
* The built-in stereotype intended for use with beans that define the model layer of an MVC web application architecture such
* as JSF.
* </p>
*
* @see javax.enterprise.inject.Stereotype
* @author Gavin King
*/
As the java doc states, this should be used on the model layer of an MVC web application like JSF, but I cannot have an idea about how a @Named @RequestScoped
bean can represent the Model layer.
If I can ask the question in a different way, how can (and why) a @Named @RequestScoped
bean be used let's say for accessing the database?
If it's not possible or a good practice or even not logical then isn't the @Model
name a bad choice for a @Named
and @RequestScoped
bean? (I would avoid using it in order not to confuse anyone reading the code)