views:

613

answers:

7

I'm relatively new to Java programming (About 2 years) but not to web development. I started out with HTML and ASP (pre .NET), and have recently started messing with J2EE. I feel like I have a good grasp of JSP/Servlets (I find them to be similar to ASP) and have recently begun working with JSF and Facelets. Although I can see why people would like JSF, I find it to be a huge burden and it's actually slowing my development times down. I imagine this is due to the learning curve, but I often find myself thinking that I would be finished with a page/task if I were just using JSP/Servlets.

Is this common to those of you who have taken the time to learn a framework? Have you ever invested time into learning a framework and once you were proficient in it, just decided to go back to a method that wasn't as sophisticated but you felt comfortable with?

I'm also questioning whether I've chosen the right framework. I was really hoping to find something that didn't interfere with adding AJAX capabilities.

+11  A: 

JSF can be tricky to get started with, and is harder to learn than many Java web frameworks. You might find it easier to use JSF with Seam, which simplifies much of how you work with JSF, and replaces JSP with Facelets, which is a great improvement.

Alternatively, you could try SpringMVC, which lots of people find easier to use.

Peter Hilton
I found the JSF learning curve to be VERY steep, but when I figured out how to use it, I actually liked it.
Thorbjørn Ravn Andersen
I second that. Very hard to learn, but once you've got it, it's a really great tool.
Ian McLaird
+1 agreed, add ajax on top of that and you will want to murder yourself in no time.
windfinder
I agree completely with the ajax on top of JSF in 1.x. They seem to have done a decent job making ajax a first class citizen in JSF 2.0.
digitaljoel
+4  A: 

I've been using facelets for a little over a year. One of the main advantages I see in Java web frameworks is that it helps to keep the code clean and promotes re-use. For instance, in facelets, you don't get any scriptlets in your pages like you do in JSP. I've seen ASP files in production that are over 3000 lines long. There's nothing inherently wrong with ASP or JSP, but it does make it quite easy to lump some business logic in the page. No harm, right? Until someone else has to maintain it.

Most frameworks try to 'help' you keep a more strict separation of MVC or whatever model they favor, which in turn leads to cleaner templates ( jsp, facelets, whatever ) and business and domain code that is automatically unit testable. Using many of the frameworks can take a bit more time up front, but save you many times that when it comes to maintenance and refactoring.

digitaljoel
+1  A: 

I think the easy answer is - how will you test it and verify it works when you make changes?

This is where the easy solutions breaks down, and you end up in maintainance hell. Unfortunately :(

Thorbjørn Ravn Andersen
A: 

SpringMVC is worth the hassle. J2EE is not.

Stefan Kendall
WHy is J2EE not worth the hassle? JEE is a lot less hassle than J2EE, but even J2EE has it's uses.
vickirk
+1  A: 

I think this depends on whether the framework genuinely solves a "difficult problem" for you, and solves it easily. People always find this a terribly controversial thing to say for some reason, but most of the frameworks I've considered using I've ending up ditching halfway through because it's just easier to Write Some Code to do exactly what I want.

Later, when I have a problem in my code, I can just go to where the problem is and add a line of code to fix it, rather than wading through pages of documentation to find the magic configuration parameter. If I have a problem with (insert favourite framework), I generally find I'm p*ssing around for ages when the underlying problem that the framework is supposed to be solving was never that complicated in the first place.

My favourite useless frameworks are ones that require lots of configuration and clumsy boilerplate code to do basic tasks such as sending some bytes down a socket or stuffing some parameters into a prepared statement and firing it off to a database. Another of my favourites are the whole raft of "XML technologies", especially ones that are "pluggable" or "configurable". (Why do I want a "pluggable parser framework" rather than just one parser that always works...?) Call me Victor Meldrew, but it's amazing how people can turn a 10-minute regular expression problem into a 2-day how-do-you-make-this-framework-with-X-in-the-title-do-it problem.

Now that said, there are people who absolutely thrive on Spring, Hibernate, JSF, MVCJammer, Joomajamaventilate, things with 'X' in them etc etc. So clearly for some people in some situations, they're a miracle, and I'm just missing out in life.

Possibly it depends on whether you or your organisation primarily have "configuration" and "plugging things together" expertese or "programming" expertese? I suppose I have more of the latter.

Neil Coffey
+1  A: 

My advice: get comfortable with lots of different frameworks, and know how to get your hands dirty and write it yourself, too. You'll develop some favorite ways to work, but you'll get a good understanding for what the tools can do, and what they can't. And you'll also develop an eye for when is the right time to use a framework, and when is the right time not to.

I've found that JSF and Facelets are definitely worth the hassle, if you can survive the learning curve. It's pretty steep, but when you figure it out, it's very easy to work with. They make managing session and application scope objects much easier to deal with than just raw JSP and servlets, and I've found that I can write cleaner Java when I don't have to think about the web in the business logic. In general, I find that the frameworks help me to organize my thoughts (and by extension, my code) in a consistent, easy to understand way.

Facelets, in particular, is my favorite web template engine. I love the fact that my pages are valid XML, and that I don't have scriptlets all over the place. It makes the code much cleaner and easier to follow if you know the framework. There's that learning curve again.

By the way, adding AJAX to Facelets is easy if you use something like RichFaces or IceFaces. They have pre-built ajax components that you can easily add to your application.

That said, it's not the best for all projects, YMMV, and so on. At the end of the day, using any framework is a judgment call. If it's not helping you solve your problem, then it's not worth it. Don't fight with your tools, use them correctly. If the tool is in your way, use a different tool. JSF and facelets are really not very good choices on a very small application. They don't really come into their own until you have a fairly complex domain model and complex business logic. Basically, you need the project to be complicated enough to overcome the amount of boilerplate code you need to write to get going.

Ian McLaird
A: 

I second SpringMVC. It's very easy to comprehend, and the code is very semantic if you use annotations. Like those Budweiser commercials...Servlets is too light...Struts is too heavy.

I wish Java had Scaffolding. It can with Grails, but that's another framework to embed within a framework.

Droo