• Post Reply Bookmark Topic Watch Topic
  • New Topic

where is the action class in JSF??

 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

In JSF how to write a action class, in Struts we have Action class and Spring we have a action class.so the request goes to the action class.

but how about JSF, i am trying to find it , but the examples shows very basic stuff, like bean with getter and setter.

how to call action class in JSF??..

please provide me information.

thanks in advance
Kishan
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no "action class" in JSF. You provide a method for your button or link that executes your prefered action. For example..



And in your backing bean, just supply this method.



You might take a look at my JSF Tutorial I wrote a while back. It still applies to current versions though.
[ January 16, 2006: Message edited by: Gregg Bolinger ]
 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply. it was very helpful.

If suppose my business method contain in another class, then how will i get the LoginForm instance???.

In struts we used to map one form with the action class.I will get the instance from action method.

here how it works??

thanks in advance
Kishan
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF works rather differently from Struts - its best to work through a tutorial first like Greg's.

Saying that... a JSF backing bean is just a POJO is doesn't extend or implement any JSF stuff, you get a FacesContext by calling FacesContext.getCurrentInstance(), this object can be used to get request params, existing backing beans populated with values from the user's request, etc.

You could think of a backing bean as an Action class.
 
Tim Holloway
Bartender
Posts: 18413
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSF backing bean is SORT OF like a Form Bean plus an Action Processor in a single JavaBean.

However, unlike Struts objects, JSF backing beans are pure POJOs, and don't have to implement any interfaces or extend and classes.

In fact, in many cases, you don't even call on JSF-specific services, nor create or access JSF specific objects. Ideally, not at all, in fact.

JSF is based on the idea of Inversion of Control, which means that the framework can be configured to inject much of what you need into the backing bean automatically. For example, the HTTP parameters are injected via property setter calls.

One of the big benefits of this is that it's much easier to test backing beans, since you don't have so set up some monstrous elaborate support frame such as a web applications container in order to do the testing. Also, since the beans are POJOs, you can lift them out and place them in other types of systems with minimal changes.
 
Arun SinghBit
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

You can use action class with JSF application. And we can get backing bean's object in Action class. So we can separate action methods from backing bean.

Please find the below link for the same:

http://myjavademos.blogspot.in/2013/10/my-first-blog-test.html

Thanks
Arun
 
Tim Holloway
Bartender
Posts: 18413
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of the people who designed JSF had worked/were still working on Struts. They found Struts to be less than ideal for what they wanted to do.

Both Struts and JSF are based on the Model/View/Controller paradigm, but whereas Struts has an architecture that's based on subclasses and interfaces (Model 2), JSF is essentially 100% pure MVC and is designed to work using POJOs.

This POJO-oriented approach was considered desirable because it means that there is potential for code re-use and unit-testing without needing to start up a cumbersome test server system. It abstracts the design away from HTTP and web-specific constructs and functions which means that the code is (theoretically) easily ported to other (non-HTTP) servers and non-HTML rendering systems. Since ideally, a JSF component has little or no JSF-specific code (other than JSF UI model objects), the application code is also well-immunized against changes in JSF itself. This is further facilitated by the fact that JSF is based on Inversion of Control (IoC), which is an operating model where instead of embedding server-specific logic in the user-written components for the purpose of locating other components, the JSF framework automatically injects those components into their targets.

Last, but not least, JSF is designed to automatically validate and transform data and to manage a cycle where fat-fingered users can repeatedly correct a form until they get all the data right. Then, and only then is the MVC model updated and the business processing initiated.

MVC is actually pretty useless by itself, since it only covers keeping Views and Models in sync with each other. Practical use requires external points to initialize the Model and process the data when requested. In JSF, this is done by action methods referenced on SUBMIT objects (commandButton and commandLink controls) and, in JSF2 also by AJAX listener action methods. The initialization part is less formally defined, but we've come up with a number of techniques over the years.

A Struts action is part Controller, part Action method. JSF's Controllers are not user-supplied code: they are pre-defined functions of the FacesServlet and JSF tag implementations, so only the business part is explicitly defined in a JSF Action method. Also, since one of the gripes the Struts designers had with Struts was the need to define separate Model and Action classes, JSF puts its action methods in the UI Model objects instead of in explicit external Action classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!