• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Passing values between pages

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im a student,just started learning JSF.Previously i had worked with Struts.
I now need to transfer a page's form data to other page.

In JSF I noticed when I created my index.jsp there was a jsf managed bean created which updated itself when i added new controls.
I just created one form and linked it with faces controller and linked the o/p to welcome.jsp.
In welcome.jsp i need to print the details i got from the form in index.jsp
Suppose it as a Name.

Do I need to create any other beans (Form beans like in Struts) for tranferring.Or is it just that way.

Help me
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for troubling you for this.
i got it right this time.

I need to know the difference between a managed bean and controller.
In previous case I outputted some string and page got automatically forwarded to other page without a controller.Then where this controller comes into play.

I also want to know why a bean is created for every jsp page i create.
Thanks in advance
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the Controller is the Controller Servlet, which you don't have to create, it is given to you.

The backing beans can be placed at different scopes, which will also determine how often a new one is created. There are also default scopes, and I believe backing beans default scope is page, so that one gets created for each request of a page. If you had the bean scoped to Session, then it gets created just once per user, and application is once per deployment of the app.

Try these tutorials

http://www.coreservlets.com/JSF-Tutorial/
http://www.roseindia.net/jsf/r/introducingjsf.shtml

and you can find some more doing a Google search on "JSF Tutorial" and also check out the Wikipedia entry
http://en.wikipedia.org/wiki/JavaServer_Faces

Good Luck

Mark
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If i can navigate from one page to other using a backing bean.Then whats the need of Faces Action(When created having a public String action() method given)

How can I use like that in struts I knw

The flow is page ->formBeans->Controller->Page

While I see in JSF
page->backingbeans->page

where these faces action comes to play?

Help me please
 
Saloon Keeper
Posts: 28214
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A managed bean is the Model in the JSF MVC framework, and the JSF Servlet is the primary controller, with sub-controllers being implemented as part of the JSF tag implementations.

A managed bean cannot navigate - at least unless you do some really horrifying coding. What a managed bean normally does is provide a data container bean and/or an action method bean. The action methods return a status string, and the JSF Navigation framework applies it to the navigation rules coded up in the JSF configuration file.

A page can refer to more than one backing bean. One thing I've done often is to keep a separate bean for search arguments and inject it (via JSF-config) into the bean that actually does the searching functions - since searching and sorting is often a sub-function of a broader function I'm doing.

I consider JSF to actually be simpler than Struts - it's a purer implementation of MVC. However, it does require a readjustment in thinking of how you do things from a logic-based viewpoint to a data object-based viewpoint.
[ March 24, 2008: Message edited by: Tim Holloway ]
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone clarify my point

In struts we do page->controller->page
While in Jsp i did using action() to go to another page
Here clearly i did using a managed bean.
Flow like page=>bean->(with help of returning string)+nav rule->page2

This isnt really violating MVC
Here in the backing bean i have to link with my business logic isnt it.Where in the struts controller separates the formbean from us.
 
Tim Holloway
Saloon Keeper
Posts: 28214
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSF is actually closer to "real" MVC than Struts is. No web-based system can ever be fully MVC, however, since webservers aren't allowed to "push" updates out to browsers - they can only wait for the next browser request.

JSF permits multiple beans to be referenced on one page, so if you prefer to put the business logic in one bean and the backing data in another, that's OK.

However, even in Struts, it's not considered good practice to put the business logic in the display interface components (formbean or action processor). Instead, the business logic is better off in a "pure" business bean so that details of the presentation mechanism don't get in its way. Struts best practices recommends that the action processor serves as an interface to business logic beans.

Since JSF allows interfacing with generic Javabeans, you could wire a business bean directly to the page. I usually don't however, since I'm using the backing bean as a for the deeper functions.
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means that I will be writing my business logic outta there in some other class and calling those classes from the action method in some backing bean /managed bean and based on that return a string for navigation?

ie like
string action1()
{
res=business_logic_class1();
//do what all I like
On res return "string1" "string2"
}
Is that true?
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dishpal Bhaluja:
It means that I will be writing my business logic outta there in some other class and calling those classes from the action method in some backing bean /managed bean and based on that return a string for navigation?

ie like
string action1()
{
res=business_logic_class1();
//do what all I like
On res return "string1" "string2"
}
Is that true?



No answers following my point.Reply needed
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dishpal Bhaluja:
It means that I will be writing my business logic outta there in some other class and calling those classes from the action method in some backing bean /managed bean and based on that return a string for navigation?

ie like
string action1()
{
res=business_logic_class1();
//do what all I like
On res return "string1" "string2"
}
Is that true?



Yes basically. For starters and learning I recommend that approach, in more complex applications later on you might find about page navigation from what action method is called or what action method just returned, but lets save that for later.

Mark
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic