• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

initial page event

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I want to, write some java code that must work while the page is loaded. For example, I want to populate the datatable in the page while the page is opening. I tried the setForm method of the page's backing bean but didnt work. The same code works if I put it under the same page's command button action. Then, I tried the constructor. The bean is in the request scope.
But in the constructor, I cant access the beans other objects. For example, there is a dataTable in the page and I want to populate it in the constructor. But when I access the dataTable object in the constructor, it gives nullPointerException in the runtime. (for ex: dataTable2.setBorder(1); throws exception in the constructor). The same code works if i put it under a command buttons action in the sam page..

I think, there must be a solution for initialization the page objects.
Thanks...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dont do anything in the constructor try writing your logic in a separate method.
 
Tugrul ...
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Logic and implementation is ready but cant find a suitable place to put.
 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are using jsf-ibm.jar , prerender may be of some help



Thanks,
 
Saloon Keeper
Posts: 28597
211
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
"Tugrul ..."

Welcome to the JavaRanch. We don't have many rule around here, but we do ask that you make your display name conform to our Naming Standards. Please read them and adjust your display name accordingly. It helps us look more professional - even if we do have a moth-eaten mooose head as our logo.

There's limits to what you can overlap in a web app, whether you use JSF, raw servlets, or PERL CGI. One of those limits is that HTTP is a request/response protocol and not a client-server one, so the only way to get any overlap at all would be to spin off a worker thread that could be picked up on the next client request. An HTTP request isn't complete until the server-side code completes.

Also, as a general rule, backing beans in JSF should not talk directly to JSF objects. That is, you wouldn't normally make a bean that seeks out a datatable and stuff things into it. Instead you define the databable to reference the backing bean and have the datatable load itself from the backing bean - which it does automatically when you set the datatable's value attribute. This is a principle known as Inversion of Control (or IoC, for short).
[ March 21, 2006: Message edited by: Tim Holloway ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,
I have a question that is also related to page initialization.

I have a web site that is database driven. When a user logs in, their profile is looked up in a database and is used to determine the next page to be displayed. For example, an administrator might be taken to a page that allows them to run special admin reports. If a user is registering for a conference, the registration is customized based on the conference being registered for. If the user is registering for conference X, conference details are retrieved from the database before the registration page opens. When the user sees the registration page it might say:
National Association Of Space Engineers New Ideas Conference
May 3 - 7 2006
Registration begins April 1, 2006

I understand how a backing bean can be used to display these values, but when and how would these values be obtained?

Thanks In Advance
Steven
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do this with a PhaseListener. Just regiser a
new listener for the RESTORE_VIEW phase, and
implement the beforePhase method; you can do this in
the backing bean's constructor, or somewhere elase.
This is pretty much the same as the Page_Load event
handler in .NET.
So far I have seen only examples which declare listeners in
faces-config.xml for the whole application (not per page).

Regards
Solmaz Anvar
 
Steven Gray
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help! I got the phase listener working. After the user logs in, they are displayed an instructions page (instructions.jsp) with a backing bean (InstructionPageBean.java). I have the backing bean coded to go out to the database and fetch the name of the image file to be displayed. Now my problem:

After logging in, the instructions page opens, but without displaying the image file.

If I click on the browser's refresh button, the image displays correctly. What am I doing wrong? Is InstructionPageBean's constructor getting called after the view is rendered for instrucions.jsp? Any help would be appreciated.

Here is the relevant code:

faces_config.xml - UserBean is a backing bean for the login screen (login.jsp).
InstructionPageBean is a backing bean for instructions.jsp.

UserBean.java

InstructionPageBean.java



instructions.jsp


[ March 30, 2006: Message edited by: Steven Gray ]
[ March 30, 2006: Message edited by: Steven Gray ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic