JSF 2.0 (Facelets) and Struts - jsf

I am a newbie with Java EE 6. I started with JSF 2.0, Facelets, Managed Beans and really liked it. It was a great switch from JSP and servlets. It also made me a confused person. It may be the lack of my knowledge, but I have many questions swirling in my mind.
Are Facelets and Managed beans a direct replacement of JSP and Servlets. (The job requirement here still focuses on JSP and Servlets, will the market/global trend move towards Facelets or the demand of JSP will remain)
What about integration of Struts 2.0, Hibernate and Spring with Java EE 6. I have seen lots of tutorials and working examples of these technologies with JSP, but havent them with Facelets.

My personal view:
JSF is built on top of JSP/Servlet -- it's not really a replacement, but a higher level abstraction.
Ideas in Hibernate and Spring have somehow been integrated under JPA and CDI.
Basic knowledge of JSP/Servlet is still usefull, what's not needed is knowledge of JSTL.
That said, there are two broad categories of web framework: component-based, and action-based. JSF is component based and each component is responsible of its own rendering and callbacks. Struts is action-based, where the controller forward to a view explicitly. Both can be seen as MVC, but the approach differ largely between the two. There are other frameworks of both types around (wicket, play, etc.)
Which kind of approach is best is subject to taste and opinion.

Struts 1 was a framework that added additional structure above a JSP/servlet application. I would develop with Struts in preference to raw JSP, and in fact many developers using JSP before Struts emerged evolved their own equivalent frameworks.
JSF is in effect a standardised equivalent of Struts 1, whose development was heavily influenced by the originators of Struts. So JSF is more or less a direct replacement of Struts, that in principle should be widely supported by Java EE App Server vendors. The adoption of JSF is not uniform, there are enthusiastic users, and otehr folks who stick with Struts 1. I have no statistics to tell you which technolgies are more widely used.
Both Struts and JSF and Model/View/Controller frameworks, and neither address how to implement the Model - in particular they don't say much about persistence, hence you need something in addition to Struts/JSF which is where Hibernate and JPA come in.
To my perception the emerging trend is to build UIs using Dojo or JQuery, with REST services, It appears that Struts 2 is attempting to address this problem domain, with rich widgets in the browser. This is interesting and worth study. Personally I've not used Struts 2, nor have I encountered it professionally, probably because I'm working with products that major on Dojo and iWidgets. I'm planning to give Struts 2 some attention.

Related

Java EE 6 app with OSGi

I had develop an application base on JSF, EJB and JPA. The JSF side with ManagedBeans and Facelets lies in the war-module and my EJBs are in ejb-module. It is not a big thing, let's say 20 pages, 15 ManagedBeans and few entities and EJBs. It's part of my bachelor thesis and one of the requirements says that I need to make this system modular and I should use for that OSGi technology.
So my knowledge about OSGi is almost none and after few hours of googling I didn't make any progress. So I'd like to ask you, how would you divide this app into modules?And can you point me to some tutorial or article where such a procedure is described?Because I didn't find anything that would fit my scenario.
It's app dedicated to managing student projects at university. So there are two roles, teacher and student. Both of them can create projects, teacher confirmes them, students them submits them.
Here is my project structure
I don't want you of course to give me a whole solution but I'll be glad if could give me something for the start.
Thanks a lot
In a nutshell, OSGI modules are provided as bundles, which can be started, stopped, modified without disturbing other parts of the application.
When you break your scenario into bundles you will have:
Service (EJB in your case)
ServiceLocator (which will be used by clients like your jsf in this case, this can be part of your client itself)
Client (JSF in your case)
i. Depending upon complexity of project, you may also break your web into separate bundles like view, dao e.t.c, but in your case I dont think this is required.
Depending upon common code that you may have in your application you may also have a common bundle.
A very good place to start with Java EE and OSGI is # Oracle Wiki

Pros and cons of integrating ZK with JBoss Seam and not using JSF?

Please could someone tell me why it is better to use ZK with JBoss Seam instead of using JSF with JBoss Seam. What are the advantages and disadvantages.
Pros of ZK + Seam: fast development cycle, easy to learn, better productivity.
Pros of JSF + Seam: default support. The power of ui objects depends on the JSF solution you choose. IMO, the most important thing for JSF to do is to define the standard set of rich widgets like Swing does. Right now, it is painful to change from one supplier to another and hard to make them work together in the same page.

What technologies are best for my application: Struts with Hibernate or Spring with Hibernate

I have a working knowledge of Struts2 and Spring. I want to develop an application that manages information for multiple companies. I am totally confused about what technologies are best for my application. For instance: Struts2, and Hibernate MVC with Spring.
Can somebody help me select appropriate technologies?
Here is a quick breakdown of a J2EE stack you can use:
Use Struts2 for your controller layer
Use Hibernate for your data abstraction layer. Create service interfaces for your DAO. The interfaces will allow you to use some type of RMI for services later if desired, meaning those services can run on different machines than your web app. Have concrete classes implement those interfaces. The classes will contain business logic and validation of data, and will wrap the Hibernate session. The Hibernate session is used to read/write to/from the database. Use Hibernate annotations to expedite the implementation of Hibernate beans.
Use Spring for instantiating your service classes and Struts2 actions. Configure Spring to inject service instances into your Struts2 actions. This is called dependency injection. Reference interfaces, not classes in your Struts2 action's setter methods for the DI.
Use the Struts2 tag library or JSTL in your JSP, which will be your view layer.
Use Maven for your builds and deploys.
Run Apache with mod_jk, and use Tomcat as your servlet container. mod_jk runs w/ the Apache process, and passes requests to the Tomcat servlet container, which lives in the JVM.
If your application requires search capabilities, use SOLR, a REST service built on top of Lucene.
Instead of using Struts2, you could also take a look at Apache Wicket.
I had the same question few days back and following are the links I used to make a decision - I settled for Spring MVC. Also check out Spring ROO if you are starting afresh.
Choosing the right web framework
Comparing web frameworks
What Web Application Framework?
Ultimately choice will be based on your needs - but above links discuss what parameters you should consider before choosing one.
Hope that helps.
Agree with #Simian, and add some comments and reasons.
From a technological perspective, you should use any framework that utilize modern and mature technologies, such as Struts 2, Spring MVC, Hibernate, JSF, and etc.
However, from a business perspective, you should take more emphasis on the business model that your project consist of, and the demand for the framework is easy and rapid to implement, as well as robust and easy to maintain.
Therefore, as you are familiar with Struts 2, and Spring, I recommend:
1, Use Struts 2 as the MVC framework of your project, but use AJAX if required. You can also develop your interceptors to fulfill some common requirements of your project.
(Or, if you have time, you can learn Spring MVC as it works well with Spring framework, and has better support of AJAX and RESTful. JSF is not recommended, not because it isn't a superb framework, but it use a set of complete different concepts comparing to Struts 2 and Spring MVC, and it is difficult for an unskilled person to debug )
2, Just use Spring jdbcTemplate as your data layer, use DAO pattern to decouple.
(Or , you can learn Hibernate or JPA as your ORM framework, if you have time.)
3, Use Spring IoC to manage your objects and integration with Struts 2 and Hibernate, and manage transactions with Spring's annotations.

Are filters or phase listers a good way to do security in Java EE 6?

I've been doing it like this lately and find it so much better than XML hell(Spring security) or Glassfish security(because I don't need to have groups or set the tables up a certain way). Is this an ok way to secure Java EE applications? Thanks!
A homegrown Filter is perfectly doable when properly written, but it's less maintainable/reuseable because it's tight coupled to the webapplication in question. Java EE container managed security and Spring Security offers an API which is the same and reuseable for every webapplication. This may end up to be easier for developers/maintainers who are working on multiple different projects and wanted to implement/maintain the same. While relatively easy to implement, a homegrown Filter simply violates the DRY.
By the way, I wouldn't recommend using a PhaseListener for this since this hooks on JSF requests only, not on other requests like static CSS/JS/HTML files and "plain" JSP files.

Using the Seam framework without Stateful Session Beans?

Has anyone had success building a SEAM Application without using Stateful session beans? There is some confusion on a new project in which I think several stakeholders have essentially 'banned' stateful session beans... but some development is being done in SEAM.
Most of the literature on SEAM encourages the use of Stateful Session Beans. Thoughts?
You can absolutely use Seam without stateful session beans. You don't need any type of EJB at all, if you don't want them. Seam can be deployed on a variety of app servers, including Tomcat which doesn't support the use of EJBs. Seam has the ability to mimic a lot of the functionality that EJBs provide -- session scope, transactions, etc. -- without actually using an EJB.
Using Seam with Tomcat, for example, you can have a very robust application without EJBs that is lightweight, but acts in a manner similar to an application deployed on JBoss or Websphere that does make use of EJBs.

Resources