Related
I'm trying to choose an AJAX-friendly Java framework for my first web application and am interested in first
understanding the architectural differences between the different flavors that are out there.
I like the concept of MVC frameworks, and so am primarily considering the following:
Any JSF variety (ICEFaces, RichFaces, PrimeFaces, etc.)
Spring Web Flow
ZK
Wicket
I've downloaded each of these projects and tried to follow their samples/tutorials, and there is
so much information to ingest I figured I'd take a breather and come here to cover some preliminaries
first.
I'm interested in how each of these frameworks implements the MVC pattern. Obviously, something rooted
in JSF (like ICEFaces) is going to have a different architecture than Spring. I'm sure that this is a
huge question, so I'm not looking for a full-blown tutorial on each of these frameworks; I'm just
curious as to what sort of artifacts (Java sources, XML config files, etc.) a developer has to write in
order to build a single AJAX-driven page using these. I'm interested in the differences to their approach,
nothing more.
For instance, I would imagine that each framework at some point uses a FrontController (or its likes) to
map HttpRequests to the right Controller implementation. That Controller (bean) would then need to do
some processing, possibly hit the database for some information (using ormapping and forming the Model), and
then construct a View/HttpResponse to send back to the client. This is an oversimplification I'm sure, but
there has to be an easy way to explain the high-level architecture for how each of these frameworks accomplishes
that.
Struts uses the ActionServlet (with Struts2 now its just Action) as the controller and model and jsp is the view.
For Spring MVC is achieved by DispatcherServlet which does the routing and Model is not bound to any framework related object you can use any.
JSF - UI jsp or jsf itself, Model - ManagedBean, Controller - FacesServlet.
I did some similar search for my own project a while ago, have a look at the links below:
Comparison based on multiple parameters : http://static.raibledesigns.com/repository/presentations/ComparingJavaWebFrameworks.pdf
Difference between JSF and Struts
http://struts.apache.org/2.0.14/docs/what-are-the-fundamental-differences-between-struts-and-jsf.html
Somewhat related post
https://stackoverflow.com/questions/7633583/which-mvc-is-better-spring-or-struts
Spring and JSF
http://blog.springsource.org/2007/04/21/what-spring-web-flow-offers-jsf-developers/
Spring MVC : http://static.springsource.org/spring/docs/2.0.x/reference/mvc.html
Best Fit For JSF Component Library: Primefaces based on my own experience
From IBM Clearing the FUD : http://www.ibm.com/developerworks/library/j-jsf1/
Hope this gives you some insight.
Have a look at Matt Raible's talk on Comparing JVM Web Frameworks here. You can also consider looking at Spring MVC and 'Tapestry`.
Also, this link gives you a matrix on capabilities of various java web frameworks.
You should also check out the Play framework. I have used it a little and really like it.
It is very easy to get started with minimal configuration (reminds me of Rails).
http://www.playframework.org/
This is really a general question.
I have an ecommerce webapp that I built solo about 4 years ago. At the time, I made the decision to use Struts as my mvc framework. As years passed working on other projects, I came to appreciate and feel much more comfortable with the feature set and flexibility offered by Spring MVC.
The service layer is solid, and is built using the spring framework.
I'd like to refactor my current web layer to now use Spring MVC. But as I have mentioned previously, I wrote the app solo and it's more of a side project. The point being that I do not have time, nor do I want to risk throwing away and completely reengineering the web layer from scratch.
So I'm asking the community on what their strategy would be for this refactoring effort?
Ideally, I would like to tackle pieces at a time, and ultimately mix the two technologies until eventually when I can completely turn off Struts.
All new functionality for my site would best be developed in Spring MVC.
The good thing is that my existing views, which is currently using apache tiles, would not have to change much, with the exception of removing struts tag libraries and replacing them with Spring MVC.
One requirement I'd like to keep is that the URL's should not change.
In other words, the ActionServlet and the DispatcherServlet would have to map to separate paths but somehow go to different implementations.
For example, how can I say that mysite.com/show-product maps to a Spring Dispatcher servlet, but mysite.com/show-category maps to a Struts action servlet.
Your thoughts are appreciated.
You can run them both in the same container with appropriate mapping.
I don't understand the question "should I convert action classes to spring controllers one at a time", how else would you do it?
Whether an action class should map to a method of a controller has more to do with your existing app's organization than anything else, or at least how you want the Spring app organized.
No, you don't need to rewrite your actions. See here:
http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/web-integration.html
Look for "18.4 Apache Struts 1.x and 2.x"
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I hear a lot about Spring, people are saying all over the web that Spring is a good framework for web development. What exactly is Spring Framework for in a nutshell? Why should I used it over just plain Java.
Basically Spring is a framework for dependency-injection which is a pattern that allows building very decoupled systems.
The problem
For example, suppose you need to list the users of the system and thus declare an interface called UserLister:
public interface UserLister {
List<User> getUsers();
}
And maybe an implementation accessing a database to get all the users:
public class UserListerDB implements UserLister {
public List<User> getUsers() {
// DB access code here
}
}
In your view you'll need to access an instance (just an example, remember):
public class SomeView {
private UserLister userLister;
public void render() {
List<User> users = userLister.getUsers();
view.render(users);
}
}
Note that the code above hasn't initialized the variable userLister. What should we do? If I explicitly instantiate the object like this:
UserLister userLister = new UserListerDB();
...I'd couple the view with my implementation of the class that access the DB. What if I want to switch from the DB implementation to another that gets the user list from a comma-separated file (remember, it's an example)? In that case, I would go to my code again and change the above line to:
UserLister userLister = new UserListerCommaSeparatedFile();
This has no problem with a small program like this but... What happens in a program that has hundreds of views and a similar number of business classes? The maintenance becomes a nightmare!
Spring (Dependency Injection) approach
What Spring does is to wire the classes up by using an XML file or annotations, this way all the objects are instantiated and initialized by Spring and injected in the right places (Servlets, Web Frameworks, Business classes, DAOs, etc, etc, etc...).
Going back to the example in Spring we just need to have a setter for the userLister field and have either an XML file like this:
<bean id="userLister" class="UserListerDB" />
<bean class="SomeView">
<property name="userLister" ref="userLister" />
</bean>
or more simply annotate the filed in our view class with #Inject:
#Inject
private UserLister userLister;
This way when the view is created it magically will have a UserLister ready to work.
List<User> users = userLister.getUsers(); // This will actually work
// without adding any line of code
It is great! Isn't it?
What if you want to use another implementation of your UserLister interface? Just change the XML.
What if don't have a UserLister implementation ready? Program a temporal mock implementation of UserLister and ease the development of the view.
What if I don't want to use Spring anymore? Just don't use it! Your application isn't coupled to it. Inversion of Control states: "The application controls the framework, not the framework controls the application".
There are some other options for Dependency Injection around there, what in my opinion has made Spring so famous besides its simplicity, elegance and stability is that the guys of SpringSource have programmed many many POJOs that help to integrate Spring with many other common frameworks without being intrusive in your application. Also, Spring has several good subprojects like Spring MVC, Spring WebFlow, Spring Security and again a loooong list of etceteras.
Anyway, I encourage you to read Martin Fowler's article about Dependency Injection and Inversion of Control because he does it better than me. After understanding the basics take a look at Spring Documentation, in my opinion, it is used to be the best Spring book ever.
Spring contains (as Skaffman rightly pointed out) a MVC framework. To explain in short here are my inputs.
Spring supports segregation of service layer, web layer and business layer, but what it really does best is "injection" of objects. So to explain that with an example consider the example below:
public interface FourWheel
{
public void drive();
}
public class Sedan implements FourWheel
{
public void drive()
{
//drive gracefully
}
}
public class SUV implements FourWheel
{
public void drive()
{
//Rule the rough terrain
}
}
Now in your code you have a class called RoadTrip as follows
public class RoadTrip
{
private FourWheel myCarForTrip;
}
Now whenever you want a instance of Trip; sometimes you may want a SUV to initialize FourWheel or sometimes you may want Sedan. It really depends what you want based on specific situation.
To solve this problem you'd want to have a Factory Pattern as creational pattern. Where a factory returns the right instance. So eventually you'll end up with lots of glue code just to instantiate objects correctly. Spring does the job of glue code best without that glue code. You declare mappings in XML and it initialized the objects automatically. It also does lot using singleton architecture for instances and that helps in optimized memory usage.
This is also called Inversion Of Control. Other frameworks to do this are Google guice, Pico container etc.
Apart from this, Spring has validation framework, extensive support for DAO layer in collaboration with JDBC, iBatis and Hibernate (and many more). Provides excellent Transactional control over database transactions.
There is lot more to Spring that can be read up in good books like "Pro Spring".
Following URLs may be of help too.
http://static.springframework.org/docs/Spring-MVC-step-by-step/
http://en.wikipedia.org/wiki/Spring_Framework
http://www.theserverside.com/tt/articles/article.tss?l=SpringFramework
Old days, Spring was a dependency injection frame work only like (Guice, PicoContainer,...), but nowadays it is a total solution for building your Enterprise Application.
The spring dependency injection, which is, of course, the heart of spring is still there (and you can review other good answers here), but there are more from spring...
Spring now has lots of projects, each with some sub-projects (http://spring.io/projects). When someone speaks about spring, you must find out what spring project he is talking about, is it only spring core, which is known as spring framework, or it is another spring projects.
Some spring projects which is worth too mention are:
Spring Security - http://projects.spring.io/spring-security/
Spring Webservices - http://projects.spring.io/spring-ws/
Spring Integration - http://projects.spring.io/spring-integration/
If you need some more specify feature for your application, you may find it there too:
Spring Batch batch framework designed to enable the development of
batch application
Spring HATEOAS easy creation of REST API based on HATEOAS principal
Spring Mobile and Spring Andriod for mobile application development
Spring Shell builds a full-featured shell ( aka command line) application
Spring Cloud and Spring Cloud Data Flow for cloud applications
There are also some tiny projects there for example spring-social-facebook (http://projects.spring.io/spring-social-facebook/)
You can use spring for web development as it has the Spring MVC module which is part of Spring Framework project. Or you can use spring with another web framework, like struts2.
What is Spring for? I will answer that question shortly, but first, let's take another look at the example by victor hugo. It's not a great example because it doesn't justify the need for a new framework.
public class BaseView {
protected UserLister userLister;
public BaseView() {
userLister = new UserListerDB(); // only line of code that needs changing
}
}
public class SomeView extends BaseView {
public SomeView() {
super();
}
public void render() {
List<User> users = userLister.getUsers();
view.render(users);
}
}
Done! So now even if you have hundreds or thousands of views, you still just need to change the one line of code, as in the Spring XML approach.
But changing a line of code still requires recompiling as opposed to editing XML you say? Well my fussy friend, use Ant and script away!
So what is Spring for? It's for:
Blind developers who follow the herd
Employers who do not ever want to hire graduate programmers because they don't teach such frameworks at Uni
Projects that started off with a bad design and need patchwork (as shown by victor hugo's example)
Further reading: http://discuss.joelonsoftware.com/?joel.3.219431.12
Very short summarized, I will say that Spring is the "glue" in your application. It's used to integrate different frameworks and your own code.
Spring is three things.
Spring handles Dependency Injection and I recommend you read Martin Fowler's excellent introduction on dependency injection.
The second thing Spring does is wrap excellent Java libraries in a very elegant way to use in your applications. For a good example see how Spring wraps Task Executors and Quartz Scheduler.
Thirdly Spring provides a bunch of implementations of web stuff like REST, an MVC web framework and more. They figure since you are using Spring for the first two, maybe you can just use it for everything your web app needs.
The problem is that Spring DI is really well thought out, the wrappers around other things are really well thought out in that the other things thought everything out and Spring just nicely wraps it. The Spring implementations of MVC and REST and all the other stuff is not as well done (YMMV, IMHO) but there are exceptions (Spring Security is da bomb). So I tend to use Spring for DI, and its cool wrappers but prefer other stuff for Web (I like Tapestry a lot), REST (Jersey is really robust), etc.
What you'd probably want in a web application with Spring -
Spring MVC, which with 2.5+ allows you to use POJOs as Controller classes, meaning you don't have to extend from any particular framework (as in Struts or Spring pre-2.5). Controller classes are also dead simple to test thanks in part to dependency injection
Spring integration with Hibernate, which does a good job of simplifying work with that ORM solution (for most cases)
Using Spring for a web app enables you to use your Domain Objects at all levels of the application - the same classes that are mapped using Hibernate are the classes you use as "form beans." By nature, this will lead to a more robust domain model, in part because it's going to cut down on the number of classes.
Spring form tags make it easier to create forms without much hassle.
In addition, Spring is HUGE - so there are a lot of other things you might be interested in using in a web app such as Spring AOP or Spring Security. But the four things listed above describe the common components of Spring that are used in a web app.
I see two parts to this:
"What exactly is Spring for" -> see the accepted answer by victor hugo.
"[...] Spring is [a] good framework for web development" -> people saying this are talking about Spring MVC. Spring MVC is one of the many parts of Spring, and is a web framework making use of the general features of Spring, like dependency injection. It's a pretty generic framework in that it is very configurable: you can use different db layers (Hibernate, iBatis, plain JDBC), different view layers (JSP, Velocity, Freemarker...)
Note that you can perfectly well use Spring in a web application without using Spring MVC. I would say most Java web applications do this, while using other web frameworks like Wicket, Struts, Seam, ...
Spring is great for gluing instances of classes together. You know that your Hibernate classes are always going to need a datasource, Spring wires them together (and has an implementation of the datasource too).
Your data access objects will always need Hibernate access, Spring wires the Hibernate classes into your DAOs for you.
Additionally, Spring basically gives you solid configurations of a bunch of libraries, and in that, gives you guidance in what libs you should use.
Spring is really a great tool. (I wasn't talking about Spring MVC, just the base framework).
The advantage is Dependency Injection (DI). It means outsourcing the task of object creation.Let me explain with an example.
public interface Lunch
{
public void eat();
}
public class Buffet implements Lunch
{
public void eat()
{
// Eat as much as you can
}
}
public class Plated implements Lunch
{
public void eat()
{
// Eat a limited portion
}
}
Now in my code I have a class LunchDecide as follows:
public class LunchDecide {
private Lunch todaysLunch;
public LunchDecide(){
this.todaysLunch = new Buffet(); // choose Buffet -> eat as much as you want
//this.todaysLunch = new Plated(); // choose Plated -> eat a limited portion
}
}
In the above class, depending on our mood, we pick Buffet() or Plated(). However this system is tightly coupled. Every time we need a different type of Object, we need to change the code. In this case, commenting out a line ! Imagine there are 50 different classes used by 50 different people. It would be a hell of a mess. In this case, we need to Decouple the system. Let's rewrite the LunchDecide class.
public class LunchDecide {
private Lunch todaysLunch;
public LunchDecide(Lunch todaysLunch){
this.todaysLunch = todaysLunch
}
}
Notice that instead of creating an object using new keyword we passed the reference to an object of Lunch Type as a parameter to our constructor. Here, object creation is outsourced. This code can be wired either using Xml config file (legacy) or Java Annotations (modern). Either way, the decision on which Type of object would be created would be done there during runtime. An object would be injected by Xml into our code - Our Code is dependent on Xml for that job. Hence, Dependency Injection (DI).
DI not only helps in making our system loosely coupled, it simplifies writing of Unit tests since it allows dependencies to be mocked. Last but not the least, DI streamlines Aspect Oriented Programming (AOP) which leads to further decoupling and increase of modularity.
Also note that above DI is Constructor Injection. DI can be done by Setter Injection as well - same plain old setter method from encapsulation.
The accepted answer doesn't involve the annotations usage since Spring introduced support for various annotations for configuration.
Spring annotations approach (Dependency Injection)
There the another way to wire the classes up alongside using a XML file: the annotations. Let's use the example from the accepted answer and register the bean directly on the class using one of the annotations #Component, #Service, #Repository or #Configuration:
#Component
public class UserListerDB implements UserLister {
public List<User> getUsers() {
// DB access code here
}
}
This way when the view is created it magically will have a UserLister ready to work.
The above statement is valid with a little bonus of no need of any XML file usage and wiring with another annotation #Autowired that finds a relevant implementation and inject it in.
#Autowired
private UserLister userLister;
Use the #Bean annotation on a method used to get the bean implementation to inject.
Spring is a lightweight and flexible framework compare to J2EE.
Spring container act as a inversion of control.
Spring uses AOP i.e. proxies and Singleton, Factory and Template Method Design patterns.
Tiered architectures: Separation of concerns and Reusable layers and Easy maintenance.
Spring is a good alternative to Enterprise JavaBeans (EJB) technology. It also has web framework and web services framework component.
Spring started off as a fairly simple dependency injection system. Now it is huge and has everything in it (except for the proverbial kitchen sink).
But fear not, it is quite modular so you can use just the pieces you want.
To see where it all began try:
http://www.amazon.com/Expert-One-Design-Development-Programmer/dp/0764543857/ref=sr_1_1?ie=UTF8&s=books&qid=1246374863&sr=1-1
It might be old but it is an excellent book.
For another good book this time exclusively devoted to Spring see:
http://www.amazon.com/Professional-Java-Development-Spring-Framework/dp/0764574833/ref=sr_1_2?ie=UTF8&s=books&qid=1246374863&sr=1-2
It also references older versions of Spring but is definitely worth looking at.
Spring was dependency injection in the begining, then add king of wrappers for almost everything (wrapper over JPA implementations etc).
Long story ... most parts of Spring preffer XML solutions (XML scripting engine ... brrrr), so for DI I use Guice
Good library, but with growing depnedenciec, for example Spring JDBC (maybe one Java jdbc solution with real names parameters) take from maven 4-5 next.
Using Spring MVC (part of "big spring") for web development ... it is "request based" framework, there is holy war "request vs component" ... up to You
In the past I thought about Spring framework from purely technical standpoint.
Given some experience of team work and developing enterprise Webapps - I would say that Spring is for faster development of applications (web applications) by decoupling its individual elements (beans). Faster development makes it so popular. Spring allows shifting responsibility of building (wiring up) the application onto the Spring framework. The Spring framework's dependency injection is responsible for connecting/ wiring up individual beans into a working application.
This way developers can be focused more on development of individual components (beans) as soon as interfaces between beans are defined.
Testing of such application is easy - the primary focus is given to individual beans. They can be easily decoupled and mocked, so unit-testing is fast and efficient.
Spring framework defines multiple specialized beans such as #Controller (#Restcontroller), #Repository, #Component to serve web purposes. Spring together with Maven provide a structure that is intuitive to developers.
Team work is easy and fast as there is individual elements are kept apart and can be reused.
Spring framework is definitely good for web development and to be more specific for restful api services.
It is good for the above because of its dependency injection and integration with other modules like spring security, spring aop, mvc framework, microservices
With in any application, security is most probably a requirement.
If you aim to build a product that needs long maintenance, then you will need the utilize the Aop concept.
If your application has to much traffic thus increasing the load, you need to use the microservices concept.
Spring is giving all these features in one platform. Support with many modules.
Most importantly, spring is open source and an extensible framework,have a hook everywhere to integrate custom code in life cycle.
Spring Data is one project which provides integration with your project.
So spring can fit into almost every requirement.
Am a bit confused here! how does spring framework assist in general development of an application? I use django framework and i can quickly explain to a layman how all parts fit together(Django, Python, templates, packages etc) to produce an excellent web application, but when i look at spring i get a bit lost! Am looking answers but not limited to the following;
Can someone please tell me how they have used spring to produce applications?
Can someone please point to me some real world applications done in spring ( iread somewhere linkedin.com is done with spring!
Can someone please tell me how this pieces come together ( Strut, javascript, glassfish/jboss, apache, etc and ofcourse spring) to produce an application?
How many separate pieces of software do you need to produce an application using spring?
How easy is it to produce application using spring framework?
I need the gory details :)
Gath
There are a number of Spring projects, but the initial Spring (POJO) project came about because of the perceived difficulties of working with J2EE. You'll find a number of projects on the SpringSource website that have grown out of this, but rather than being lumped into one framework they've taken a more modular approach. For all the products they produce see:
http://www.springsource.org/projects
Q. Can someone please tell me how they have used spring to produce applications?
Spring provides a number of features, but the most oft used one is that of dependency injection. This allows you to wire together components (e.g. Javabeans) by declaring the relationships in XML/Annotations. The Spring container then reads this information and constructs the bean hierarchy at runtime. A standard way to describe the beans in XML is the Application Context.
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html
Q. Can someone please point to me some real world applications done in spring ( iread somewhere linkedin.com is done with spring!
There are lots of applications built using Spring. I'm not sure of big commercial projects, but I expect there to be many.
Q. Can someone please tell me how this pieces come together ( Strut, javascript, glassfish/jboss, apache, etc and of course spring) to produce an application?
Spring is normally integrated with other frameworks, there are various hooks into these frameworks and you need to look at each one separately in order to understand what they are all about. Struts and Spring framework integration can be found here:
http://www.ibm.com/developerworks/web/library/j-sr2.html
With Glasshfish/JBoss it's more about how you configure your application in relation to Spring rather than the application server. See this:
http://static.springframework.org/spring/docs/2.5.x/reference/web-integration.html
Q. How many separate pieces of software do you need to produce an application using spring?
e.g. A web application would consist of Spring MVC + Spring Backend. A desktop application - Java Swing + Spring backend. In terms of the Spring framework itself (configured with XML) it would involve:
Create your standard JavaBean classes (for services/DTO's/DAO's)
public class ExampleBean {
private AnotherBean beanOne;
private YetAnotherBean beanTwo;
private int i;
public ExampleBean(
AnotherBean anotherBean, YetAnotherBean yetAnotherBean, int i) {
this.beanOne = anotherBean;
this.beanTwo = yetAnotherBean;
this.i = i;
}
}
Declaring beans within your application context file
Integrate Spring with your web application/application via web.xml etc...
These are taken from the Spring docs btw... see:
http://static.springframework.org/spring/docs/2.0.x/reference/beans.html
Q. How easy is it to produce application using spring framework?
Very easy, but again dependent on what you're building. If you're just using the Spring POJO framework to build a service and integration tier then it's fairly simple. If you have to build a web application layer, then it's a little more complicated (not hugely at all) to understand the internals.
Hope that helps...
Can someone please tell me how they have used spring to produce applications?
Put the Spring JARs in your CLASSPATH, follow the Spring idiom (e.g., interfaces to delineate layers), and use it to glue your code together.
Can someone please point to me some real world applications done in spring ( iread somewhere linkedin.com is done with spring!
Here's one. Running in production now for three years and counting.
Can someone please tell me how this pieces come together ( Strut, javascript, glassfish/jboss, apache, etc and ofcourse spring) to produce an application?
Struts is one choice for web tier; JavaScript is something you can use to make your client dynamic; Glassfish/JBOSS/WebLogic/WebSphere/Tomcat/Spring DM are all app server choices for deploying your Spring app; Apache is an HTTP web server; Spring and your code go on the app server.
How many separate pieces of software do you need to produce an application using spring?
You need an app server and probably a database, a browser, your code and Spring.
How easy is it to produce application using spring framework?
How good a programmer are you? Depends on your knowledge.
Spring certainly made my life easier once I understood it.
Spring is a pretty large framework, it's going to be hard for anyone to summarize everything here. I think the biggest plus for using Spring is its dependency-injection support. It can be used in any type of application, and provides a ton of framework features and utilities. If you are really interested, I'd recommend starting with the docs on springsource.org:
http://www.springsource.org/documentation
There are a lot of tutorials out on the web too. To fully appreciate it, you should try writing a few example apps to get the feel for it, and see what's available.
Just to add another dimension - if you are interested in building java web apps, and have no constraints (like legacy code to integrate with/update), then take a look at grails. its the best-est web framework to write web apps in. Of course, it uses spring internally too, but its fairly abstracted away from you. In fact, i'd liken it to django.
You can start with this http://static.springframework.org/docs/Spring-MVC-step-by-step/. This will provide the basic framework for you and then spring is huge so depending upon what you need you can explore spring and use it.
This has worked for me.
If you're talking about Struts and JavaScript at the same time, it means that you don't know what you're talking about, for Web Development in general.
What is what?
- You have frameworks in Java such as Spring, Struts, etc. which help you build Java based Web applications. Those Java Frameworks integrate generally Web with ORM tools, and other technologies.
- You have Servlet Containers such as Tomcat, Jetty, etc on which you can run classic Java Web Applications. J2EE containers such as JBoss, Glassfish embed a servlet Container such as Tomcat and provide a J2EE container and sometimes other tools, to deploy Java Enterprise applications.
Choosing a Framework
Choosing a Framework depends on how you feel about it and how it fits your needs. For example why are you using Django instead of TurboGears? Some people will tell you that Django sucks while TurboGears rocks, etc.
Whatever you do it's your call, read at the documentation and pick one application server and one or many frameworks to build your application.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
What is the difference between Oracle ATG and Struts?
Struts is a framework for using within a J2EE web application that tries to provide web applications with an MVC-pattern based approach to coding. It includes some added utilities for form data validation etc. It is an open source project, and has been quite good at solving that particular piece of the web application puzzle, and is limited to only solving that particular piece.
ATG (ATG Dynamo), on the other hand, is an application platform - a solution and a framework - for building data- and content- driven web applications - largely for commerce and publishing. At the framework level, it is a Java based application platform for hosting web-based applications, as well as RMI accessible business components, with an ORM layer, a component container, an MVC framework, and a set of tag libraries for JSP. The component framework (The Nucleus) is a lightweight container for managing the life cycle and dependency binding (dependency injection) of Java component objects (beans). In that sense it is somewhat similar to the Spring bean container, and is the core of the ATG framework - all other services and frameworks are hosted within it. The ORM layer framework (Repositories) maps objects to and from relational databases (as you would expect). But it can also handles mapping with LDAP, XML and file system data ources using the same consistent data access API. The JSP tags for binding form elements on a page to values on business objects etc. are more elegant and cleaner than the form binding tags in any other framework I have seen. The mechanism of writing your own tag library equivalents (Droplets) is much more consistent with the Servlet API than standard J2EE tags.
The MVC framework (the basic Form handler pattern) is somewhat similar to Struts Form and Action classes - but provides a much more basic framework that Struts does. Out of the box, and at the level at which most developers work, the ATG model is page-driven not controller-driven. Internally, it is certainly controller-driven with a pipeline approach to chaining dispatchers and controllers.
In addition, the framework at the basic level gives you an RMI container, distributed caching, distributed locking and distributed singletons, distributed events and messaging, a task scheduler, a rules engine and a mechanism for defining business workflows with custom actions and outcomes, a graphical editor for business workflows, support for versioned data, support for roles and rights, logging and auditing - all out of the box, and all using very coherent and consistent APIs
Then at the solution level, you have the components and the APIs for dealing with user profiling, identity management and personalization, content authoring, versioning and publishing, content search, product catalogs for tangible and intangible goods, product search and guided navigation, pricing, tax calculation, promotions, shopping carts, gift lists and wish lists, payment types, shipping methods, order tracking, customer relationship management etc.
The extension points and integration points to ATG are usually very well designed and quite well documented. They support integration with pretty much anyone who is anyone in the e-commerce and publishing space for things like authoring and content management, identity management and security, product catalogs, search and guided navigation etc. Also, almost all areas of the framework are extensible and plug-gable so you can write your own components to enhance or replace the ones out of the box.
It does not really make much sense to compare the two. However, given your question, I imagine what you are really interested in is the MVC part of ATG
For MVC, Struts gives you more than ATG does (but then Spring MVC gives you even more than Struts does). However, you tend to get bogged down in the mechanics of the framework far more with Struts than with ATG.
Personally, I think that ATG's form-handler based model is more elegant, cleaner and easier to work with than most other web MVC frameworks I have seen, and the APIs are more consistent with the Servlet APIs.
Bear in mind, also, that most 'web-MVC' frameworks are not like true MVC (i.e. the pattern used for GUI programming in Smalltalk or even Java Swing etc.). Neither Struts nor ATG provide (as designed) true MVC - though ATG actually comes closer. There is a lot of confusion about terminology.
For example,
the Model in true MVC is not your data model nor your domain model objects. It is the model that represents all the data in a view. If that happens to be a domain model object then well and good - but more often than not, you will find that you need a different set of view or form objects. Also, the model is responsible for keeping itself updated - it is the Model that interacts with business services lower down. ATG tends to fuse the model and the controller into one component - the form-handler. Struts tends to keep the view data model distinct (the form object), but does not encourage its use as a model in the true MVC sense - it is not the form object that interacts with other business services to keep itself updated.
the Controller in MVC is not your business controller. A controller in MVC is a conduit between the view and the model. It reacts to changes in the view, or to actions performed on the view, and instructs the model to update itself accordingly. In Struts the Controller they talk about is not an MVC controller at all - it is really a dispatcher. A lot of the code that belongs in a controller ends up in your Action class. But the way Struts is designed, the Action class is really meant to do what a Model does.
the View in MVC should be populated by the model - it is a push mechanism with the model updating the view, not a pull mechanism with the view querying the model. In most web-MVC frameworks, the view (usually a JSP) pulls state from the model in order to display itself. This is particularly the case with ATG's page-driven approach. If you find that data is being fetched while your page is rendering it means something is wrong with your MVC design.
In Struts, the function of the MVC Controller is spread across the Struts controller and the Action, while the function of the MVC Model is spread across the Form object and the Action.
In ATG, the function of the MVC Controller and the MVC Model is all in the Form-handler
Having said that, due to the request-response nature of HTTP, the function of a Controller in a web-MVC framework is quite limited. With web applications, we tend to get a completely updated view on form submission rather than lots of small changes (e.g. each key press or mouse click, or each changed input field) as we would with a rich UI framework. The use of AJAX is changing that - and we have to think much more about implementing MVC correctly.
Remember, MVC is a design pattern - i.e. it is a design-time principle to be used when designing the GUI aspect of applications. Struts, and ATG are frameworks - i.e. they are classes and objects to be extended, implemented or configured when building your application. A framework cannot enforce the use of a design pattern - it can merely encourage it. Choosing to use a particular framework will not make you design your ciode better - at most it may encourage a certain discipline.
If you design your MVC well, it will not make a huge difference whether you use Struts classes or ATG classes to implement it. Likewise, if you design your MVC badly, hoping that your choice of framework will make up for your shortfalls, it will not make a huge difference whether you use Struts or ATG. If you understand and work with the design principles, you will find it very easy to switch back and forth between frameworks.
The best code will be that which adheres to a good design principle (say, true MVC) in the abstract, and implements it (realizes it) using the right tools available in the chosen framework in the way they are intended to be used.
Coming back to your question;
If you are working on an ATG project, you should use the frameworks that ATG provides. It is certainly possible to shoehorn Struts into an ATG application - I have done this myself many years ago - but it is far more effort than it is worth - and you are giving up a lot of what ATG provides out of the box in terms of object life-cycle management, form data binding etc..
If you are about to start work on a new project and have a choice of frameworks to use - I would personally recommend an open source application server (like JBoss) and the Spring Framework - it gives you the best of what ATG and Struts provide. It has a Nucleus-like component container (the Application Context), it integrates with all good ORM solutions (such as Hibernate) and includes an MVC framework that in my opinion has far eclipsed Struts. In addition, I would recommend looking at Spring Web-flow for higher level GUI flow design.
The main difference in the UK is that as an ATG contractor you can get £500 per day, but as a general Struts guy you're lucky to get £350.
Not that I'm bitter at all.
ATG is proprietary software... and resources are less ...