Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace @ManagedBean with @Named #2

Open
agoncal opened this issue May 28, 2015 · 22 comments
Open

Replace @ManagedBean with @Named #2

agoncal opened this issue May 28, 2015 · 22 comments
Assignees

Comments

@agoncal
Copy link

agoncal commented May 28, 2015

In your JSF example, you use the JSF @ManagedBean and @RequestScoped annotations. Both have been pruned in Java EE 7 and should be deprecated in next version. Instead you should use the CDI @Named and the CDI @RequestScoped.

@TheCoder4eu
Copy link
Owner

Hi Antonio,
thank you very much for pointing this out, I'll change it ASAP!

@stephanrauh
Copy link
Collaborator

Bonsoir Antonio,

first of all I'm glad you discovered our project!

As for your suggestion: actually, I had thought quite a few minutes about which annotations to choose. You know, the old JSF annotations may have been deprecated in Java EE 7, but there's no @deprecated in the JSF 2.2 source code, so Eclipse won't tell me about it. BTW, BootsFaces is also targeted at JSF 2.0 and 2.1, both of which don't support CDI. As a consequence, the dependency tree of our showcase project doesn't include the javax.inject.jar.

Another consideration is Spring. Personally, I'm very fond of CDI, but I didn't want to drive the Spring developers away, so I decided to use the old annotations. But maybe you're right: these days Spring supports @nAmed and @Inject, too.

Best regards
Stephan

@stephanrauh
Copy link
Collaborator

Funny thing is my new PollDemoBean accidentially uses the CDI annotations. So much for "I've thought about it thoroughly" :).

@agoncal
Copy link
Author

agoncal commented May 28, 2015

Yes, Spring uses @Named and @Inject. Unfortunately it doesn't support the CDI @RequestScoped. Java EE being built more and more on CDI, and Spring that doesn't support it... I think that, unfortunately, both programming model will start to shift and you will have to choose one or the other :o(

@stephanrauh
Copy link
Collaborator

Maybe we should think about a pull request enhancing the SpringBeanAwareELResolver. It's not difficult to add the view scope to Spring, let alone the CDI request scope (see ViewScope and faces-config.xml).

@TheCoder4eu
Copy link
Owner

The classes using @ManagedBean are:

src/java/org/primefaces/showcase/view/input/CalendarView.java:@ManagedBean
src/java/net/bootsfaces/demo/BarcodeBean.java:@ManagedBean
src/java/net/bootsfaces/demo/LoremIpsumBean.java:@ManagedBean
src/java/net/bootsfaces/demo/SettingsBean.java:@ManagedBean
src/java/net/bootsfaces/demo/InformBean.java:@ManagedBean
src/java/net/bootsfaces/demo/TestBean.java:@ManagedBean(name = "testBean")
src/java/net/bootsfaces/demo/ClockBean.java:@ManagedBean
src/java/net/bootsfaces/demo/ItemBean.java:@ManagedBean
src/java/net/bootsfaces/demo/SemaphoreBean.java:@ManagedBean
src/java/net/bootsfaces/demo/DateBean.java:@ManagedBean(name = "dateBean")
src/java/net/bootsfaces/demo/CarBean.java:@ManagedBean
src/java/net/bootsfaces/issues/issue78/SoccerTeamBean.java:@ManagedBean

The classes using @RequestScoped are:

src/java/net/bootsfaces/demo/LoremIpsumBean.java:@RequestScoped
src/java/net/bootsfaces/demo/SettingsBean.java:@RequestScoped
src/java/net/bootsfaces/demo/InformBean.java:@RequestScoped
src/java/net/bootsfaces/demo/TestBean.java:@RequestScoped
src/java/net/bootsfaces/demo/ClockBean.java:@RequestScoped
src/java/net/bootsfaces/demo/ItemBean.java:@RequestScoped
src/java/net/bootsfaces/demo/DateBean.java:@RequestScoped

@TheCoder4eu
Copy link
Owner

Btw, Antonio, I see you have made a presentation titled "To inject or not to inject: CDI is the question":
choosing the right annotation is not always straightforward in JEE...

@agoncal
Copy link
Author

agoncal commented May 28, 2015

"choosing the right annotation is not always straightforward in JEE". Yes, I agree. I'll think of something simple... maybe a matrice with service == annotation (eg. transaction == @transactional, injection == @Inject). Something to blog about ;o)

@zhedar
Copy link
Collaborator

zhedar commented Apr 7, 2016

I would like to resurrect this issue, because as of JSR 330 CDI is part of Java EE 6, which is the minmal version BootsFaces supports. So using CDI should be an option for everyone who uses JSF 2.0+, since it's part of the same JEE specification.
The only part of CDI, which requires JSF 2.2 and therefore Java EE 7 is CDI's missing support of JSF's ViewScoped.

If we like to keep supporting JSF 2.0 in this showcase, we might just use OmniFaces' ViewScoped implementation, which offers CDI ViewScoped support in both JSF 2.0 and 2.1. We have a dependency to OmniFaces anyway, so might as well use that.

@stephanrauh
Copy link
Collaborator

BootsFaces supports Java 6, not JavaEE 6 :). Modern application servers have become very good, but there are still a couple of developers using a pure Tomcat or even Spring with JSF.

@zhedar
Copy link
Collaborator

zhedar commented Apr 7, 2016

I misinterpreted BootsFaces is targeted at Java EE 6/7 and requires a Java 1.6 or later VM. in the requirements then, my bad. I just know, that PrimeFaces requires the jee6-spec and therefore it would be something, that most libraries do.

However shouldn't be those limitation only be applied to the project itself? I just thought CDI won't hurt the showcase. But I also somehow understand the decision to keep things minimal.

@stephanrauh
Copy link
Collaborator

Thing is, our official showcase runs on Wildfly, but I run the same sources on a local Tomcat. It's easy to define a profile for the dependency. But that's not enough. You need some boiler plate code to activate CDI on a Tomcat. I didn't find out yet how to move that into a Maven profile. Plus, I'm not sure if the result is worth the pain. This kind of things tends to get ugly. But if there's a simple solution, I'm game!

@ggam
Copy link
Collaborator

ggam commented Apr 8, 2017

Now that JSF 2.3 is out and the old annotations are effectively deprecated, I think it's time to do the change.

Also, have in mind that some JSF features now require CDI in order to work (like the new [FacesDataModel](https://javaserverfaces.java.net/nonav/docs/2.3/javadocs/javax/faces/model/FacesDataModel.html which is implemented as a CDI extension).

For plain Servlet containers, instructions will need to be added on how to enable CDI. For Spring users, maybe we should point to http://joinfaces.org/.

@stephanrauh
Copy link
Collaborator

@TheCoder4eu @zhedar @ggam @asterd @chongma Which target platforms do we want to support with BootsFaces 1.1.0?

  • Java 7
  • Java 8
  • Tomcat and Jetty
  • Java EE only

BTW, we can't support Spring because JSF is incompatible with it. For instance, the ViewScope is broken and won't be fixed.

@chongma
Copy link
Collaborator

chongma commented Apr 9, 2017

I use TomEE 7.0.2 with OpenJDK 1.8.0 on CentOS. TomEE is a packaging of the various EE libraries into a Tomcat installation. People should be upgrading to the new stuff but it depends how much you want to support backwards compatibility.

My projects are already converted to CDI as I was told by Apache team that @ManagedBean was going to be deprecated as Oracle is trying to standardise all the managed containers into one - hopefully eventually including Spring. It was a fairly painless conversion just required changing the annotations.

Apache team also told me that Oracle plan to deprecate javax.* in Java 1.9.0 and they are not quite sure what that will mean yet as they were originally told to put all the Enterprise stuff in the javax package.

@ggam
Copy link
Collaborator

ggam commented Apr 9, 2017 via email

@stephanrauh
Copy link
Collaborator

The problem with embracing the CDI annotations is that we exclude the Spring Boot community. That doesn't bother me too much because Oracle already expels them actively, but still, it might reduce the acceptance of BootsFaces.

The reason why I'd love to switch to Java 8 is defender methods. We've got a lot of boiler-plate code copied over and over again. Maybe the default methods of Java 8 could alleviate the pain.

@ggam
Copy link
Collaborator

ggam commented Apr 9, 2017 via email

@stephanrauh
Copy link
Collaborator

Yes, I know JoinFaces. I'm even loosely in contact with the author. Thing is, JoinFaces can't solve this problem: https://www.beyondjava.net/blog/updating-to-mojarra-2-2-11-may-break-your-spring-boot-application/

In fact, Manfred Riem told me that the JSF team won't even try to maintain compatibility to Spring. That's the root of the problem: if Oracle is eager to break compatibility with Spring, we can't do anything about it. Maybe they'll change their mind, but I don't think so. The current strategy of aligning everything with CDI makes so much sense, compatibility to Spring is a minor issue in comparison.

@ggam
Copy link
Collaborator

ggam commented Apr 10, 2017

So how does JoinFaces work if CDI beans are broken?

I haven't used Spring nor Spring Boot. Not calling ServletContainerInitializers seems like an odd decision since the spec mandates Servlet containers to call them. I can't blame Mojarra's team for using that.

Anyway, people using JSF with Spring must be aware of the limitations. I think we can confidently change our annotations to the CDI ones and create a new page about Spring and JoinFaces in the integrations section, explaining how to use them both.

From what I read on the issues, it seems to work with MyFaces. Since Spring users are usually not tied to specific servers, why not just pointint them to MyFaces?

@stephanrauh
Copy link
Collaborator

Spring uses the SpringBeanFacesELResolver to map JSF annotations to Spring beans. So Spring and Spring Boot don't use CDI at all. The just use the same annotations. Most of the time, you won't notice the difference, but advanced JSF feature simply won't work. Such as the ViewScope.

@stephanrauh
Copy link
Collaborator

Recommending MyFaces might be an interesting option. I didn't try that myself yet, but the approach sounds promising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants