Question

I made a simple xhtml page for upload file by using <h:inputFile> component. And everything works fine. And in managed bean I used dependency injection for the Logger. I used a factory class and createLogger() method in, to enable injection for object of Logger class. Everything is ok but, nothing works without a @Model annotation in managed bean.

Can somebody explain the meaning of the @Model annotation.

I can not find on internet proper explanation. A founded explanation of other annotation like as @Session, @Request, @Application etc.

What does the @Model annotation do?

Was it helpful?

Solution

Hej vmaric,

@Model == @RequestScoped + @Named

It exposes the Backing Bean directly to your JSF 2 or JSP and its context will be destroyed after the end of the servlet request.

So it should not be used for entities.

Here is a hint from the Weld Reference Guide:

Notice the controller bean is request-scoped and named. Since this combination is so common in web applications, there's a built-in annotation for it in CDI that we could have used as a shorthand. When the (stereotype) annotation @Model is declared on a class, it creates a request-scoped and named bean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top