This discussion is archived
1 2 Previous Next 19 Replies Latest reply: Oct 9, 2012 5:43 AM by Cvele_new_account RSS

How to execute action method programmatically?

765291 Newbie
Currently Being Moderated
Hi all,
I'm using Jdev 11.1.1.5.0

I have created two pages pg1,pg2 with a template(template consists button). in the page pg1 I dragged a taskflow(consists fragment) as a region.
In the fragment bindings, i added an action.
I need to click the button to navigate from pg1 to pg2. but before navigate from pg1 to pg2, i need to execute the action which is added in the bindings of the fragment.
so, i created a bean and tried to execute that action through binding container in the button action listener.

bindings = getBindings();
OperationBinding act = bindings.getOperationBinding("Rollback");
act.execute();

but i get the nullpointer exception at the line act.execute()

I thought it is becuase, button is on the template, and the Rollback iis addRed as action binding on the fragment.

so, how can I execute that Rollback action.
  • 1. Re: How to execute action method programmatically?
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    but i get the nullpointer exception at the line act.execute()

    this is most likely because

    OperationBinding act = bindings.getOperationBinding("Rollback");

    returns null. Make sure it is in the PageDef file for the view or the method activity the code is executed in

    Frank
  • 2. Re: How to execute action method programmatically?
    765291 Newbie
    Currently Being Moderated
    Hi Frank,
    Thanks for your reply.

    That Rollback action is in the pagedef of the fragment.

    that button is on the template.
    when this line is executed in the actionlistener of the buttton, OperationBinding act = bindings.getOperationBinding("Rollback");
    it gives the null pointer exception, because Rollback action is not in the pagedef of the template.

    so, How can I access that rollback action which is in fragment pagedef from the button action listener which is on the template?
  • 3. Re: How to execute action method programmatically?
    Cvele_new_account Expert
    Currently Being Moderated
    If I understood correctly, what you need, is a RichRegion.queueActionEventInRegion() method.

    So, have CommandButton inside fragment, which calls Rollback action as usual. The button can bee non-visible.
    Then, from template button actionListener, you can use queueActionEventInRegion() method.

    +"The queueActionEventInRegion(…) method queues an ActionEvent so it behaves as if you queued it on a UIXCommand component existing inside the region or nested region."+

    For details, take a look at:

    http://www.oracle.com/technetwork/developer-tools/adf/queueactioneventinregion-155252.html
  • 4. Re: How to execute action method programmatically?
    codigoadf Oracle ACE
    Currently Being Moderated
    Hi.
    This wll help you: [url https://blogs.oracle.com/jdevotnharvest/entry/how_to_invoke_adf_bindings]How-to invoke ADF bindings in page templates.
  • 5. Re: How to execute action method programmatically?
    Cvele_new_account Expert
    Currently Being Moderated
    - As I understood, the action is not in the template's pageDef, but in the fragment pageDef.
    codigoadf wrote:
    Hi.
    This wll help you: [url https://blogs.oracle.com/jdevotnharvest/entry/how_to_invoke_adf_bindings]How-to invoke ADF bindings in page templates.
  • 6. Re: How to execute action method programmatically?
    codigoadf Oracle ACE
    Currently Being Moderated
    Yes, you are right.Sorry
  • 7. Re: How to execute action method programmatically?
    Cvele_new_account Expert
    Currently Being Moderated
    One example how to do what you want, without even the hidden button on the fragment:
        richRegion.queueActionEventInRegion("#{bindings.Rollback.execute}",  null, null, false, 0, 0, PhaseId.INVOKE_APPLICATION);}
    Try it this way.
  • 8. Re: How to execute action method programmatically?
    hofespet Journeyer
    Currently Being Moderated
    Hi,

    In our application which consists of one jspx (+ some page templates, ...) and all pages are realized with regions we just put the Rollback and Commit binding to the page def of the page template.
    So the buttons on the page template can access this binding.

    Isn't this also the solution for your problem?

    regards
    Peter
  • 9. Re: How to execute action method programmatically?
    codigoadf Oracle ACE
    Currently Being Moderated
    another way is find the pageDef of fragment through findBindingContainer (it will work)
    but is a best practice define the operations in the correct pageDef context.

    what hofespet says, is a good suggestion, another is http://www.oracle.com/technetwork/developer-tools/adf/learnmore/79-global-template-button-strategy-360139.pdf
  • 10. Re: How to execute action method programmatically?
    765291 Newbie
    Currently Being Moderated
    Hi all, thanks for Ur replies...
    Yes, my button is on template and i want to access the action method which is on the fragment bindings.(not accessing the template bindings on page)

    *richRegion.queueActionEventInRegion("#{bindings.Rollback.execute}", null, null, false, 0, 0, PhaseId.INVOKE_APPLICATION);}*

    how to use this ?

    if U don't mind can U just explain little bit more ?

    This is scenario:
    In the fragment , i add a new row in a table using createinsert,
    after this i'm trying to navigate to page2 by through command button(which is on template, and its property immediate true, added check uncommitted data behaviour, and has action outcome )
    I kept on uncommitteddatawarning property for two pages and kept .

    while navigating from page1 to page2
    get the uncommtteddatawarning box, click ok, I want to rollback all the changes done in fragment,
    thats y i want to execute the rollback action in button actionlistner.
  • 11. Re: How to execute action method programmatically?
    765291 Newbie
    Currently Being Moderated
    i added the rolback on page bindings and tried to access .
    its worked fine. rollback action executed.
    but when i navigated from page 2 to page1, while loading that fragment got the error ORA-02074.
  • 12. Re: How to execute action method programmatically?
    Cvele_new_account Expert
    Currently Being Moderated
    Here is example:

    Since you have taskFlow dropped on the page as a region, you also have af:region, right ?
    Give him id propery, for exampe richRegion
    Bind that af:region on some backing bean property:
       <af:region id="richRegion' binding="#{myBean.richRegion}" ../>
    In the backing bean, you will have something like that:
    private RichRegion richRegion;
     ....
    public void setRichRegion(RichRegion richRegion){
       this.richRegion = richRegion;
    }
    
    public RichRegion getRichRegion() {
       return richRegion;
    }
    Finally. on the template's button actionListener, you only need to put that one line of code:
          richRegion.queueActionEventInRegion("#{bindings.Rollback.execute}",  null, null, false, 0, 0, PhaseId.INVOKE_APPLICATION);}
    {quote:title=User0256 wrote:}{quote}

    *richRegion.queueActionEventInRegion("#{bindings.Rollback.execute}", null, null, false, 0, 0, PhaseId.INVOKE_APPLICATION);}*

    how to use this ?
  • 13. Re: How to execute action method programmatically?
    765291 Newbie
    Currently Being Moderated
    hi,
    I have used the code like this in the button action listener

    FacesContext fc = FacesContext.getCurrentInstance();
    ExpressionFactory ef = fc.getApplication().getExpressionFactory();
    ELContext elc = fc.getELContext();
    *MethodExpression me = ef.createMethodExpression(elc, "#{bindings.Rollback.execute}", String.class, new Class[] { });*

    *projectSetupRegion.queueActionEventInRegion(me, null, null, false, 0, 0, PhaseId.INVOKE_APPLICATION);*

    it dint throw any error while execution, but no rollback is done,
    i have checked by changing *#{bindings.Rollback.execute}* to *#{bindings.Rollbackwrong.execute}*

    still it din throw any error.

    I'm not getting where i'm missed.

    any suggestions please...
  • 14. Re: How to execute action method programmatically?
    Cvele_new_account Expert
    Currently Being Moderated
    Have you tried as I said in my previous message ?
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points