• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

richfaces: prerender method in backing bean

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

This is my first post in JavaRanch.

Firstly, some background on my java web application development experience. I have previously developed a web application using Visual Web JSF (the IDE is NetBeans 6.5, and GlassFish V2 as the application server) - this is my only experience in java web application development so far.

I'm now beginning to venture into RichFaces. I encounter a problem in some of the backing beans of my RichFaces pages, where I need to retrieve data from database and then use these data to populate the values of the components (mostly output text fields and comboboxes) when the page is rendered for the first time, but the datasource is not available and hence, I am not able to do what I wanted to do.

This is my scenario:
In the first page user selects a command link, in the backing bean of page1 the action of the command link will assign a value to a session variable and then navigates to the second page.
In the second page, I will check if the session variable is not null in page2 backing bean, if true then I will use datasource to connect to database to retrieve data, and then use the data to populate the fields in second page. But I do not have method like prerender( ) where the datasource is already initialised and usable.

Previously in Visual Web JSF Page I can do this in the backing bean's prerender() method, but using RichFaces I don't know where this prerender() method (or something similar) going to come from.

I spent many days trying to search for information in the internet, found Apache Shale framework but it has recently retired, so I decided not to use it first unless I have no other choice.

Other information I found, such as on the JBoss Seam and MyFaces Orchestra, are just too complicated and confusing for my level of experience. I only wanted something that can do init() and prerender() in my backing bean.

Appreciate if anyone can advise me how it can be done (including maybe ask me to forget about Visual Web JSF way of development but please show me the "right" way how a web application employing RichFaces components should be developed), or direct me to a relevant tutorial website.

Thanks in advance.

 
Ranch Hand
Posts: 99
MyEclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't understand the problem.

Define a session backing bean for the second page. In the command method get this bean from the FacesContext and fill it with data. Then just render the page having your elements' values set to the same bean. Don't forget to declare keepAlive element with your backing bean as parameter for richfaces ajax operations.
 
Wen Ping Fong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akaine,

Thanks for your reply, and sorry for the late, I was away.

I will try the your suggestion. Will post the result or maybe ask further question after I try. I haven't used FacesContext to get a bean, nor use the keepAlive element before, so might post my result a bit later because I need to learn those things first.

Thanks again.


 
Wen Ping Fong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Akaine,

I think your suggestion works.

I did some tests by following the information I found in the following post on JSF - Managed Bean to Managed Bean Communication:
https://coderanch.com/t/214436/JSF/java/JSF-Managed-Bean-Managed-Bean#1021122

and was eventually led to BalusC's blog on Accessing Another Managed Bean:
http://balusc.blogspot.com/2006/06/communication-in-jsf.html#AccessingAnotherManagedBean

In my small testing web project, I managed to retrieve the data from the database in one of the backing beans, and then use another bean to set the field values.

However, in the JSP I had to change the outputText from binding

to

Otherwise, the outputText component will not be shown. I'm not sure why, maybe it is due to my setup.

Anyway, at least it works in my testing! I will use this in my code to see if it works.

Thanks for your help!

 
Akaine Harga
Ranch Hand
Posts: 99
MyEclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's correct. In this approach you should use values directly. Binding is supposed to be used for element structure alteration.
 
and POOF! You're gone! But look, this tiny ad is still here:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic