r/java • u/AgilNaoEhTI • May 07 '24
Are you still using JSF for frontend?
I’m curious about what you guys use as tech stack for creating frontends. Java offers alternatives such as JSF but it has a lot of problems (ex: http session) so I was thinking if is something better in the Java world or if you use another tech, based on javascript, for example. I also see a lot of java courses that cover JSF, but I question if this subject is still relevant or might be misleading for begginers.
15
Upvotes
32
u/CloudDiver16 May 08 '24
I know I'm going to get a lot of downvotes for this, but... here we go.
I've read a lot of arguments in the comments that I'd like to address in a collected way.
Age is not a good criterion for choosing a technology.
I've read a lot of arguments that JSF is 20 years old and I just can't understand that. Java is almost 30 years old. Linux is 33 years old, Windows is almost 40 years old, and JavaScript is also 30 years old. Maturity is an advantage, not a disadvantage. But age is not a good criterion for choosing a technology. Much more important are the community and active development.
JSF is part of the Jakarta ecosystem and is under active development with most component frameworks. But the community has been shrinking in recent years. It has excellent support and has had updates without breaking changes for years.
With JSF, many things are done out of the box that need to be considered in pure JS frontends. For example, in terms of security, JSF forms include CSRF tokens in addition to the http only cookie.
With many JS frameworks, these problems are handled with server-side rendering. It's called backend for frontend (BFF) in the microservice architecture. However, this then introduces additional complexity into the architecture and unnecessarily increases latencies and resource consumption for a single backend. The biggest disadvantage of JSF, session handling, is also present here.
JSF defaults to the EJB definition, but in my last application I was able to use JSF in a pure Spring Boot application without any problems.
Similar to the discussion about monolith vs microservice, the answers here also seem to me to be much too evangelistic and in my opinion the topic belongs in this discussion.
Each of the solutions has its pros and cons, but none of them should be ruled out per se today.
JSF is very well suited for:
SPA/JS has its clear advantages in:
If a project requires exactly these points, I'll consider JSF as a front end.
As with so many things in IT, it always depends on the specific use case, requirements and available resources. So pick the best fit for your project.
13
u/davidalayachew May 08 '24
Not JSF, but I use Java almost every single day for building client side desktop front ends.
I use Java Swing and (rarely) JavaFX.
I wouldn't say JSF is misleading, just maybe not as valuable as other frameworks. Pick the best fit for your project. In short, experiment.
9
u/InstantCoder May 08 '24
Nowadays I’m using Quarkus Qute/Renarde (typesafe reactive templating engine) with htmx. Much easier to use than all those JS frameworks.
8
u/hadrabap May 08 '24
JSF is my favorite tool for small front-ends for configuration purposes. As I'm not a front-end developer, it makes no sense to me to learn every time I need it new *script frameworks and build CI pipelines for it. It is not economical. I build backends in Jakarta EE and MicroProfile. JSF is free for me.
And to make things clear: JSF doesn't depend on EJB. It works with CDI as well. It was a long time ago when JSF abandoned JSF managed beans in favor of CDI.
And finally: there's nothing wrong with EJB nowadays. In fact, it is still a great tool. 🙂
11
u/[deleted] May 08 '24
JSF is the JakartaEE standard (aka, the "Java world") for component based web interfaces in Java, while Sevlets/JSP is the standard for request/response driven web pages. JSF allows for component libraries like PrimeFaces to exist.
JS based frontends are independent of Java and fall outside of the scope of Java specifications (aka, not the "Java world"). When you go the JS route, typically Java isn't used for UI at all, but for implementing the API (such as using JAX-RS) that is used by the JS front end.
When speaking of a Java course, you have to ask what is being taught and what is the point of the course? JSF might be a valid choice as a teaching tool, since you don't have to also teach a beginner how to set up a multi-language and multi-platform toolchain.
9
u/redikarus99 May 08 '24
The modern way is to build a backend providing a REST interface and separate frontendes written in some framework (Vue, angular, react, etc.). All the big frameworks in Java support that perfectly (Spring, Quarkus, etc.)
If you by whatever reason you want to have server side rendering, there are a dozen of options.
You can also use solutions like Vaadin.
4
u/[deleted] May 08 '24
Only for back office apps and rarely customer facing ones if I know it will be used by a limited number of users. Regardless, you need to minimize state as much as you can.
4
u/henk53 May 08 '24
Well, I just posted this the other day:
https://github.com/primefaces/primefaces/releases/tag/14.0.0
Essentially the bulk of Faces (JSF) development uses PrimeFaces, so the energy put into PrimeFaces (commits, number of contributors), may be some indication of how much Faces is still used.
Every release of PrimeFaces gets a ton of enhancements, so at least there's quite a bit of activity there.
2
u/Fit-Long-9159 May 14 '24
See Chapter 9 of "Enterprise JSF" for a comparison between JSF and React.
https://github.com/e-Contract/enterprise-jsf/releases/download/enterprise-jsf-1.13.0/enterprise-jsf.pdf
Problem with most opinions out there, is that they are written by freelancers that want to put as much recent frameworks on their CV as possible. Hence JSF gets slammed in favor of the latest JS kid on the block. But, if you do a somehow objective comparison, and are aware of the pros/cons of JSF/JS, there is actually very little reason to jump into the JS, hydration, whatever-they-call-it-these-days mess.
I've tried out several JS frameworks as replacement for JSF in the past. They all start nice but once you get past the "tutorial level", it's pain all over the place. With JSF it's at least honest pain right from the start. :)
2
u/janoschbock May 08 '24
we use jsf at work, it is mostly a past down thing from our old senior dev. At first my mind was blow because he introduced us to Spring boot. Before we had this IBM shit called XPage, man was that garbage. So in this comparison JSF with PrimeFaces was for me just (good) Magic. Now a days I would prefe to use Hilla and React or use Vaadin for the full java experience in Front and Backend
2
u/tomwhoiscontrary May 08 '24
I've been working in Java full time since 2008, and never used JSF! Started with good old JSP, then moved somewhere where we had some sort of in-house framework that I've forgotten, then went to a Spring shop where it was all Spring MVC and Thymeleaf, now at a place where it's almost all JavaScript front ends fed by APIs.
If I was starting from scratch today, I'd use JAX RS + jte + HTMX where needed. Simple, web-centric, minimal JavaScript.
1
u/glablablabla May 08 '24
The last project I encountered a JSF frontend was in 2014. I like working with such frameworks like angular, react or Vue on the frontend way more because they are more flexible and powerful than JSF. For a simple and standard frontend, JSF would still be a viable solution I think.
1
u/kakakarl May 08 '24
Been off it since 2018, was deep into it before. I think primefaces was not great. Plenty of bugs and issues over the deep end. My knowledge is now outdated.
Our last app used just omnifaces with pure myfaces and did js webjars for getting a nice UI and that worked great.
Even though I know it really well I don’t use it anymore. Prefer an API and a frontend stack with testing in mind. Howe
-5
u/jr7square May 08 '24
I don’t quite get frameworks like this. Generally if I’m building a back office app I wouldn’t write in Java to begin with. And if I’m building something customer facing I would do a Java backend with some JS framework.
-4
u/_AManHasNoName_ May 08 '24
No.