Sunday Apr 09, 2006

It's been awhile, been busy making sure new Articles and Tutorials are tested and ready
for the web. Also, testing bug fixes and some changes, TBD. And developing new testcases
to help identify performance issues.

Since there hasn't been much documentation on Java Studio Creator's lifecycle, I'll mention
a couple of common questions about the lifecycle.


1) (For a Java Studio Creator Web Page) why is backing bean function like bean's constructor, init() ,prerender and others called twice for every page. First when loading the page(which is normal) and second time when leaving the page, e.g clicking a link?


Here's the order described:

Use case: Page1 processes a postback and navigates to Page2:
------------------------------------------------------------------------------- ----------
* JSF executes Restore View on Page1

* Framework calls Page1.init()

* If the application calls isPostBack() from here through destroy(), it will return true

* Framework calls Page1.preprocess()

* JSF executes Apply Request Values, Process Validations, Update Model Values, and Invoke Application on Page1

* NOTE - Update Model Values is when model data is updated through value bindings

* JSF creates new view for Page2

----------------------------------------------------------------


To resolve this for code not to be reexecuted when clicking a link (such as
executing database queries using the CachedRowSet DataProvider, place the code in prerender()

Here is the expected order of lifecycle methods called for a Page1 to Page2 navigation:


Page1:init() called
Page1::beforeApplyRequestValues() called
Page1::preprocess() called
Page1::afterApplyRequestValues() called
Page1::beforeProcessValidations() called
Page1::afterProcessValidations() called
Page1::beforeUpdateModelValues() called
Page1::afterUpdateModelValues() called
Page1::next button action called
Page1::beforeRenderResponse() called
Page2:init() called
Page2::beforeRenderResponse() called
Page2::prerender() called
Page1::afterRenderResponse() called
Page2::afterRenderResponse() called
Page1:destroy() called

2) Same question as #1 except in this case, the code not to execute twice is in a Page Fragment:


Note: in Creator 2, Page Fragments do not contain a prerender() method.


Answer from Craig :


Not having prerender() callbacks in a fragment is a current limitation. In the past, I have worked around this by defining a public method in the fragment's class, and then calling that method from the prerender() method of the surrounding page bean(s). The call would look something like this:


Fragment1 fragment1 = (Fragment1) getBean("Fragment1");
fragment1.fakePrerender();


There are several examples of this technique in the JumpStart Cycles sample application, where it is used to keep the calculations in the price table up to date.


For more examples and discussion on using the Java Studio Creator lifecycle, see the
recently revised Tutorial, Understanding Scope and Managed Beans and also see the
article, Understanding Event Processing Lifecyle

Comments:

Actually, I just have a small question. I am a very inexperienced Java Studio Creator user (BEGINNER!)

I created a navigation between two pages by dragging from a button on the first page to the second page. When running the program, clicking the button does navigate me to the second page, but none of the code in either the second page's constructor or prerender method is executed.

Does the "case" actually construct an instance of the second page? And does the "case" call the prerender method?

Thanks :)

Posted by Linda on October 13, 2008 at 01:48 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed