pattern for run a method on start of the page only 1 time

108 views
Skip to first unread message

akhanof

unread,
Jul 1, 2009, 7:58:04 AM7/1/09
to ADF Enterprise Methodology Group
Hi,

Regarding to invoke a method in the page start up and only one time I
am looking for the best pattern to use;
because using the (refresh condition= not post back) is some times
invoked more than one time making it inappropriate when we absolutely
need to run the method only 1 time .
is there any other option or pattern except setting the refresh
condition="#{!adfFacesContext.postback}" for execution of the method
on the invokeaction for method on the page bindings.

Thanks and regards,
Amir

Vik

unread,
Jul 1, 2009, 5:48:50 PM7/1/09
to adf-met...@googlegroups.com
hie

why dont you make ur method side effect free second time..

Thankx and Regards

Vik
Founder
www.sakshum.com
www.sakshum.blogspot.com

Marcos Ortega

unread,
Jul 1, 2009, 7:13:44 PM7/1/09
to adf-met...@googlegroups.com
That's a great question ; Frank;



     Earlier this week , 

       I posted this thread at otn jDev's forum too; but no cookies for me !

       As i describe there, to work around this "so many call's" I; early check if my viewObjects parameter are set  and if the value is equal my current params;

       So depending on the target viewObject's parameters; I set or not and  re-execute the viewObject;


     Other behavior that I would like to insert here, is how we can coordnate the execution of onChangeEvent (from any faces component) and onLoadPage ( or prepareModel ) phase;

     if we log this two methods we will have;

        on Log window;

              Hi there ... from prepareModel (loadPage)  
              Hi there ... from onChangeEvent
              Hi there ... from prepareModel (loadPage)


    Do we have some "best pratices" for this ?? 

    Or perhaps i'm missunderestanding something ....


Thanks too;


      Marcos Ortega
 Analista de Sistemas
  Campo Grande - MS
http://www.santoandrea.com.br


2009/7/1 akhanof <amir....@gmail.com>

Avrom Roy-Faderman

unread,
Jul 1, 2009, 10:38:27 PM7/1/09
to adf-met...@googlegroups.com
For a VO method, I think a bind variable (to hold a "this method's already
been executed" flag) is probably the best way to do this. For a view row
method, use a transient attribute (make sure it's marked for
passivation--see below). For an application module method, you could try
setting a value on the Map returned by
ApplicationModuleImpl.getSession().getUserData().

One thing you *don't* want to do is just make a field and store your flag
in that, unless you're willing to override methods like
prepareForPassivation() and activateState(). If you just use an ordinary
Java field, the value could disappear if the application module gets
recycled.

Best,
Avrom

> That's a great question ; Frank;
>
>
> Earlier this week ,
>
> I posted this
> thread<http://forums.oracle.com/forums/message.jspa?messageID=3586332#3586332>at
--
Avrom’s Java EE and Oracle ADF Blog
http://www.avromroyfaderman.com

Marcos Ortega

unread,
Jul 1, 2009, 7:53:20 PM7/1/09
to adf-met...@googlegroups.com
Some times, 
    we don't know  if the event was executed (user change some UI component), for example , if the onChangeEvent Handler is at one backing bean , and the onPageLoad is on another manage Bean;





      Marcos Ortega
 Analista de Sistemas
  Campo Grande - MS
http://www.santoandrea.com.br


2009/7/1 Vik <vik...@gmail.com>

Steve Muench

unread,
Jul 2, 2009, 5:02:23 AM7/2/09
to adf-met...@googlegroups.com
We strongly recommend using a methodCall activity in a task flow to perform any kind of "at page startup" logic in JDev/ADF 11g. It works reliably for page- as well as page-fragment-based use cases, including when "lazy" content delivery is used (which causes an additional page lifecycle (i.e. http roundtrip) to the server to lazily fetch data for the table/tree/graph. We no longer recommend using the invokeAction executable for this purpose due to their not existing any viable EL expression to use to detect the "first time render" that works in all possible scenarios.

fnimphiu

unread,
Jul 2, 2009, 2:35:37 PM7/2/09
to ADF Enterprise Methodology Group
Folks,

this thread is missing some structure.

Amir, you don't mention a JDeveloper release, but from your
"condition="#{!adfFacesContext.postback}" mentioning I point it to
10.1.3, which makes Steve's effort in answering your question a waste
of time, which should not happen on this group. To address your
question, can you identify the phases in which the method is invoked ?
If for example the method is invoked twice in a single phase then a
flag helps to prevent double execution. If it is executed in two
different phases then you may look at the setting of the refresh
option. If you have this set to ifNeeded then execution happens twice.
Set it to prepareRender or prepareModel and this should help already.

Frank

On Jul 2, 11:02 am, Steve Muench <steve.mue...@gmail.com> wrote:
> We strongly recommend using a methodCall activity in a task flow to perform
> any kind of "at page startup" logic in JDev/ADF 11g. It works reliably for
> page- as well as page-fragment-based use cases, including when "lazy"
> content delivery is used (which causes an additional page lifecycle (i.e.
> http roundtrip) to the server to lazily fetch data for the table/tree/graph.
> We no longer recommend using the invokeAction executable for this purpose
> due to their not existing any viable EL expression to use to detect the
> "first time render" that works in all possible scenarios.
>
> On Thu, Jul 2, 2009 at 1:53 AM, Marcos Ortega <mar...@santoandrea.com.br>wrote:
>
> > Some times,     we don't know  if the event was executed (user change some
> > UI component), for example , if the onChangeEvent Handler is at one backing
> > bean , and the onPageLoad is on another manage Bean;
>
> >       Marcos Ortega
> >  Analista de Sistemas
> >   Campo Grande - MS
> >http://www.santoandrea.com.br
>
> > 2009/7/1 Vik <vik....@gmail.com>
>
> > hie
> >> why dont you make ur method side effect free second time..
>
> >> Thankx and Regards
>
> >> Vik
> >> Founder
> >>www.sakshum.com
> >>www.sakshum.blogspot.com
>

Marcos Ortega

unread,
Jul 2, 2009, 1:45:29 PM7/2/09
to adf-met...@googlegroups.com
Hi , Steve;

    Lets supose a page invoked from a main menu , it would be point to a "pre-configure-page" method, that prepare the model and than redirect to the target page ?


   My application ( I think that is a good example ) has current_project as global variable, and all the data rows must be filtered by this "current_project" ;  so, as we can have severals page-flows; is a good aproche to have one manage bean in each page-flow where we have all pre-calls methods ?


    I was doing this job using page life cycle beans ....


  Thanks !!



      Marcos Ortega
 Analista de Sistemas
  Campo Grande - MS
http://www.santoandrea.com.br


2009/7/2 Steve Muench <steve....@gmail.com>

Steve Muench

unread,
Jul 4, 2009, 4:18:33 AM7/4/09
to adf-met...@googlegroups.com
I generally avoid managed beans for anything except complex UI manipulation or complex conditional navigation. I'd recommend putting any knid of "initialize task flow" type of logic related to setting up the data as a custom application module method that can be exposed on the client interface of the AM and invoked declaratively by a methodCall activity on a task flow in 11g.

In 10.1.3, the invokeAction executable was the preferred approach to trigger the same method binding to invoke the "initialize" method, but in 11g we have a more robust, self-documenting, and easier-to-understand approach with the methodCall activity.

amir hosein khanof

unread,
Jul 11, 2009, 8:37:51 AM7/11/09
to adf-met...@googlegroups.com
Hi,

Thanks for Steve MethodCall activity in the Task Flow is easy, reusable,separate logics, fortunately I am working with 11g R1 and the thing here is that when I drag and drop a method from datacontrol to the Task Flow as the start point and default activity of the task flow when the task flow is invoked (embed in a popup) I face the error oracle.jbo.InvalidOperException: JBO-25221 regarding the mentioned pattern can anyone suggest me what is wrong as I have noticed the mehod is not even invoked at all.

Thanks and regards,
Amir

Steve Muench

unread,
Jul 12, 2009, 4:44:56 AM7/12/09
to adf-met...@googlegroups.com
If a simple example of calling the same method in a default activity works fine when used outside of the taskflow-in-a-popup scenario, then likely the problem is that you have missed some step in correctly setting up your region in a popup as documented in David Giammona's whitepaper on OTN here:

http://www.oracle.com/technology/products/adf/patterns/popupregionpattern.pdf
Reply all
Reply to author
Forward
0 new messages