开发者

JSF vs. plain JSP + Beans?

I have the option of doing my next project in either JSF or JSP. Other languages/frameworks are not an option.

I don't want to use any of the visual component libraries like RichFaces, IceFaces, etc, because in the past I've had very bad experiences with them, so I'll be cherry-picking jQuery comp开发者_如何学Pythononents to do exactly what I want them to do.

Similarly I won't be bothering with data access components.

Moreover since JSF comes with many restrictions over JSPs (e.g. no support for GET, cannot avoid being stateful, etc.), I'm considering going JSP+Beans all the way.

Are there any other things I'll be missing from JSF?


The restrictions you speak of are not really there. JSF absolutely supports GET. It has in fact always supported this, although with some limitations. What you did was injecting #{param.some_id} into your bean and taking some action in a @PostContruct annotated method.

With JSF 2.0 this support has been greatly expanded and you can attach standard validators and convertors to them, something you couldn't do in JSF 1.x.

The advantages of JSF are many, but one particular thing I missed when doing plain JSP development is having a library of convertors and validators available. No matter what kind of web development you do, and no matter how fancy your client-code is, eventually some operation has to be performed on the server and then you have to do conversion and validation.

With JSF you can easily build your own library of those convertors and validators, or choose from many of the ones that are already available. With bean validation (Java EE 6) this can be taken to the next level: annotate your entities with constraints and JSF will enforce those for you in the UI. (note that JSF itself doesn't contain bean validation, but it supports it).

Then I also found that having a simple but effective templating language can be very helpful. Even if you only use few or maybe no JSF components at all, you can create master template pages, have template clients and put your jQuery based javascript and HTML in chunks that you can easily reuse at the server side. JSP really only has jsp:include for templating, which is rather limiting.

Another small handy thing with JSF is that you have easy programmatic access to the request and response objects corresponding with the current request. If you're not taking advantage of many of JSF's core features, then in JSP/Servlet style programming this can be a small advantage.

But as BalusC already indicated, maybe JSF is not for you. The greatest benefit is when using the framework for its components. If you don't plan on using these, some request based might fit you better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜