What is the purpose of integrating JSF with Spring [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
JSF and Spring are two different web frameworks. I would like to ask two questions to clear things in my head:
what is the purpose to use this 2 frameworks together ?
i have heard that JSF is for view tier. So can we make a complex web
application containing a business logic only with JSF?
Could someone explain? Thanks

Ans
1. We integrate two frameworks to exploit best features of both of them.
In your case JSF is one of the best framework for view(UI) part and spring is good at maintaining beans because of its feature DI(Dependency Injection).
Ans 2. the main goals of creating jsf were
Create a standard UI component framework that can be leveraged by development
tools to make it easier for tool users to both create high-quality UIs and manage the
UI’s connections to application behavior.
Define a set of simple, lightweight Java base classes for UI components, component
state, and input events. These classes will address UI lifecycle issues, notably
managing a component’s persistent state for the lifetime of its page.
Provide a set of common UI components, including the standard HTML form input
elements. These components will be derived from the simple set of base classes
(outlined in #1) that can be used to define new components.
Provide a JavaBeans model for dispatching events from client-side UI controls to
server-side application behavior.
Define APIs for input validation, including support for client-side validation.
Specify a model for internationalization and localization of the UI.
Provide for automatic generation of appropriate output for the target client, taking
into account all available client configuration data, such as the browser version.
Provide for automatic generation of output containing required hooks for supporting
accessibility, as defined by the Web Accessibility Initiative (WAI).
yes you can create a complex application only with JSF but its lot easier to use it with some other framework like Seam , Spring etc
Source JSF Complete reference

Related

Best practices for clean domain model [closed]

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
I'm looking for some best practices for developing a clean domain object model. By 'clean', I mean a domain (or business) model that isn't cluttered up with a bunch of DB persistence, xml/json serialization/deserialization, dependency injection stuff. For example, I've read thru several 'how-to' tutorials about implementing the REST API. When they all get to the point of implementing the 'model', they all end up having some annotations about transforming from the 'pojo/poco' to the xml/json view via [XmlAttribute], or making the field be more user friendly in the UI via [Display/Display Type] attribute. The platform doesn't matter, I've seen the cluttering in the Java world (not familiar with other scripting languages).
I'm aware of the Data Transfer Object design pattern as those objects could use these attributes, but is this the only method? DTO seems like it would require a lot of object mapping to/from view to the business layer. If that's what it takes to have a clean domain layer, then great, just looking for feedback.
Thanks
The simple truth is that all of that "annotation clutter" rose up out of a rejection of all the "XML clutter".
Taking both JPA and JAXB in Java as examples, all of those annotations can be replaced by external XML files describing the same meta data for the underlying frameworks. In both of these cases, the frameworks offer "ok" defaults for unannotated data, but the truth is few are really satisfied with the Convention over Configuration default mappings the frameworks offer, and thus more explicit configuration needs to be done.
And all of that configuration has to be captured somewhere, somehow.
For many folks and many applications, the embedded meta data via annotations is a cleaner and easier to use than the external XML mapping methods.
In the end, from a Java perspective, the domain models are "just" objects, the annotations have no bearing, in general, outside of the respective frameworks. But in truth, there's always some coupling with the frameworks, and they have a tendency to influence implementation details within the model. These aren't particularly glaring, but the simple fact is that when there may be two ways to model something, and one way is "more friendly" to the framework, for many that's enough to tilt the decision to go in that direction rather than fighting for purity above the framework.

Service model vs Extender model? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I just finished thoroughly reviewing the Apache Felix Application Demonstration with shapes. The article state:
When creating an OSGi-based application there are two main orthogonal
issues to consider:
Service model vs. extender model
Bundled application vs. hosted framework
The first issue is actually a general issue when creating OSGi-based
applications. There are two general approaches that can be used when
creating an extensible OSGi application. The service model approach
uses the OSGi service concept and the service registry as the
extensibility mechanism. The extender model approach uses the OSGi
installed bundle set as the extensibility mechanism. Both approaches
have their advantages and disadvantages and they can be used
independently or together.
I think it is a commonly accepted best practice, regarding the second point, to prefer a bundled application, unless for a really good reason you are compelled to use a hosted framework.
Regarding the first point, after having studied both the service model and the extender model I understand the differences between them, but I'm still trying to figure out what are the advantages and disadvantages to the different models.
What are the advantages and disadvantages to each model (Service vs Extender) and what are the best practices for determining which one to use or when it would be appropriate to use a combination of both?
Services are more commonly used and they should normally be your first choice unless you have a compelling reason to design a new extender.
OSGi is a service-oriented platform. A service API forms a contract between two parties, a consumer and a provider. The contract is defined in terms of a Java package containing interfaces, and the provider provides it by implementing those interfaces. The consumer uses the service registry to find instances of an interface it wants to use.
The extender pattern is somewhat more flexible and abstract, but more complicated to understand and use. Essentially, an extender bundle provides additional functionality on behalf of some other bundle(s), which normally opt in by containing some kind of declaration.
For example, suppose you want to implement a Help System for your application. Bundles could simply contain an HTML document under some agreed path, and the central Help System bundle could scan bundles to find these docs and add them to the main Help Index. Doing this with services would be quite cumbersome: assuming you follow the "whiteboard" style you would have to define a HelpProvider Java interface with a getHelpDocuments() method; every bundle wishing to provide help would have to implement this interface and register it as a service. On the other hand, the Help System extender bundle needs to be relatively smart because it has to track bundles coming and going. But at least you only have to write this smart code once.
Real-life examples of extenders are as follows:
Declarative Services is an extender that looks for the Service-Component declaration in other bundles and does all kinds of stuff on their behalf – instantiating components, publishing services etc.
Blueprint is an extender that does something similar. It looks for the Bundle-Blueprint declaration, or XML files under an agreed path.
The OSGi enterprise specification defines a JPA extender that looks for bundles containing a persistence.xml file declared by the Meta-Persistence header. When it finds one it creates a Persistence Unit for that bundle.
Eclipse contains an extender (confusingly called the Extension Registry) for creating things like Views, Perspectives, Menus etc. These are all declared in a plugin.xml file in the root of a bundle.
To summarise... services are used for registering and finding objects based on a contract. Extenders are for extending the functionality of bundles, usually based on some kind of declarative resource or header rather than executable code.
The extender model is mainly used for frameworks. It needs to look quite deeply into the bundle impl to do its work. So it is not good for loose coupling. The advantage is that it can define a completely new abstraction like blueprint or declarative services or cdi. All these frameworks use the extender model to wire your bundle based on a spec.
The service model is the right thing for your application itself. Services allow to hide the details of the implementation as well as the instantiation from the user of a service. So this is very good for loose coupling.
In the end both are typically used together. For example you can use cdi annotations to wire your bundle inernally and specify that you offer and consume services. So the cdi framework leverages an extender to wire your bundle internally while you use the service model to loosely connect your bundles.

Java Terminology/Lingo [closed]

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 8 years ago.
Improve this question
I primarily come from a PHP background but I have been asked to develop a website using the Java platform. I have been exposed to some terminology that I don't quite yet understand and I was hoping that anybody with Java familiarity could let me know in basic terms what it means/is used for. Or if you could tell me its equivalency in the PHP world that would be great too. The words are:
Spring
Struts
JavaBeans
EJB
JMS
Servlet
Thanks!
First of all most of them are Technologies that have been wrapped up around Java EE architecture. First of all do you understand what MVC stands for. MVC is Model-View-Controller pattern. It is a design principle that lets you separate your concerns easily. There are couple of PHP frameworks that follow MVC pattern. Eg:- Kohana
Spring
Spring is an MVC aritecture but beware it's not just for MVC... Spring has loads of uses. If you have used frameworks related to PHP such as Zend or CakePHP you could say that Spring is similar to them. You can checkout the Spring features.
Struts
Struts is a Front End controller. It takes all the requests and map them to their relevant actions. Here is a part from Apache Struts website
One way to separate concerns in a software application is to use a
Model-View-Controller (MVC) architecture. The Model represents the
business or database code, the View represents the page design code,
and the Controller represents the navigational code. The Struts
framework is designed to help developers create web applications that
utilize a MVC architecture.
Here are the basic components of Struts.
A "request" handler provided by the application developer that is
mapped to a standard URI.
A "response" handler that transfers control to another resource
which completes the response.
A tag library that helps developers create interactive form-based
applications with server pages.
PHP equivalent for this should probably be the Routes module in a PHP framework. Some helpful sources to easily get started with Struts -
Struts for dummies
JavaBeans
Java beans are rather simple. They follow a standard. Here are the
followed conventions - The class must have a public default
constructor (no-argument). This allows easy instantiation within
editing and activation frameworks.
The class properties must be accessible using get, set, is (used for
boolean properties instead of get) and other methods (so-called
accessor methods and mutator methods), following a standard naming
convention. This allows easy automated inspection and updating of
bean state within frameworks, many of which include custom editors
for various types of properties. Setters must receive only one
argument.
The class should be serializable. It allows applications and
frameworks to reliably save, store, and restore the bean's state in
a fashion independent of the VM and of the platform.
If you found above explanations harder to understand that's fine since Java Beans can be explained by an example simply.
public class Student implements java.io.Serializable{
private String name;
private Integer id;
public Student(){}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setId(Integer id){
this.id=id;
}
public Integer getId(){
return this.id;
}
}
More helpful sources from - Wikipedia. Probably this is a PHP class.
EJB
EJB - Enterprise Java Beans. This probably doesn't have a PHP alternative. EJB is bit complex. It's kinda of like a mega bean that has business logic around it. Best place to find more is Wikipedia -
JMS
JMS stands for Java Messaging Service. JMS provides communication in between Java applications. JMS is a technology and there are many provider implementations of it. Best I heard of happens to be HornetQ. Beware that I haven't used it. There is no PHP counter part as I know.
Servlet
Servlet is what takes the request and provides controller logic. Servlet routes the files back again to a JSP - which a Java Server page. This can be your PHP frameworks controller code.
Many Java enterprise technologies have been standardized in the Java Platform, Enterprise Edition. Even those that aren't part of the standard are often related to it in some way, for instance because they implement parts of Java EE, or attempt to improve on (replace) parts of it. Therefore, the standard is a good resource to get an overview over what libraries exist and what they do. Admittedly those specification documents make for rather dry reading, so Oracle has provided a tutorial, too.
Ok, that should cover the standard technologies (in your list: JavaBeans, EJB, JMS, Servlet).
Spring is actually a portfolio of libraries. You are probably looking for the Spring dependency injection container (which is a replacement for EJB / CDI), but Spring also offers a web framework and many other things.
Struts is a web application framework, replacing Java EE JSP.

How to organise my code in order to be able to use two different view type? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I have setup my models and now I would like to build the application so that I can easly switch between swing views and html views (2 differents builds).
Could you recommand me any library that let me do that ? or a Controller/View architecture that let me do that myself ?
edit: MVC architecture in java is the point of my question, if I use SWING my controller call the method of a View class to show the results, whereas (at least in python django) the controller returns a "View" class (and something takes care of rooting the resulting view to the user, possibly getting the view from cache directly if it's already there.) which is 2 different ways to implement MVC. I don't know how html views are sent to the user with Java (I suspect that there is different methods) that's why I'm asking the question to get the general idea behind MVC architecture in Java as it may have it's own ideomatic/reference interface to achieve this job.
Oracle's Application Development Framework (ADF) does just this.
You develop your application modules, database entities, and view objects. Then you can drag and drop them onto the page or frame. This allows you to develop the business logic once and keep the logic for handling each view separate.
JDeveloper 11g (the IDE for developing software using ADF) handles AJAX well. It also allows you to declaritively create custom components that can be reused via drag and drop.
The application's visual layout is somewhat abstracted through custom tags, but you cannot, for example, create a web page and then click a button to create a corresponding JPanel. (To my knowledge.)
I don't know of any library, but I can suggest a kind of architecture.
I suggest using (at least) three projects: one for the core functionality, one for the HTML view and one for the Swing. The views depend on the core functionality project, but the two views do not know each other.
You will need some kind of Factory in both view projects, that can instantiate the classes of the selected views using the data from the core projects - if you want to handle this instantiation from the core project, then you will need either a common interface and some kind of dynamic instantiation, or use the same class in the same package in both project.
If you choose a solution like this you cannot use both views in the same time (at least easily :) ).
OSGi with its updated classloader provides support for such scenarios, where your Java projects are OSGi bundles, their dependencies are explicitely set, and the framework can handle these ones. And you can use services to describe the view factories, and then you could decouple these parts in a formal, well-defined way.
I hope the base idea was clear enough.
I'm not sure any library will achieve what you wish. After all, each technology (swing and html) will require different 'view' layer code. What's important here is to keep all business logic out of the view layer and keep it in a control layer which is then used by each view (otherwise known as the MVC architechture, see this link for more info or Sun's more detailed example.
Basically it will come down to your dedication in maintaining separation of responsibilities which will enable you to gain the most reuse out of your code.
I googled for 'swing' and 'ajax' - because I knew of eclipse RAP project, the rich ajax platform which would help if you weren't focussed on swing - and this blog entry looked promising: http://www.javalobby.org/java/forums/t101605.html
The 'RAP' idea is to have one GUI code base and build it either for a standalone client application or a web application (ajax). The blog discusses a different approach: you build a swing application and transform it to a web application.
Hope it helped! (hope I got your question right ;) )
MVC, if followed to the dot can accomplish this! Keep all your business and model layer separate, then have struts/spring controller decide the view.
Maintain separate swing and html code.
The key again is to remove all possible business logic from presentation layer and making sure your business layer is independent of the presentation layer.
Another option is to just use Swing to display html. If you use JEditorPane or JTextPane and just show html. The downside is that you can't do very sophisticated html using this method. You might also consider using a browser in your app. Here are a couple of possibilities though I have not tried them:
http://jrex.mozdev.org
http://lobobrowser.org/java-browser.jsp
http://www.webrenderer.com/

Difference between Oracle ATG and Struts? [closed]

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 ...

Categories