You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Andrew Robinson <an...@gmail.com> on 2006/11/29 23:47:29 UTC

Re: Action chaining

Just call the action method of another bean from the action method
invoked by the UICommand componen.

On 11/29/06, Amit Kushwaha <bl...@googlemail.com> wrote:
> Hi.
>
> Is there a action chaining like functionality for managed beans?  For
> ex, I'd like the result of a managed bean invoke a method in another
> managed bean which takes the user to a view.
>
> I have tried, to-action-id but that didn't work. Am dealing with pre JSF
> 1.2.
>
> TIA.
>
> Regards.
>
> Amit
>
>
>

Re: Action chaining

Posted by Amit Kushwaha <bl...@googlemail.com>.
Thanks guys for your suggestions. I will try these out asap.

Andrew Robinson wrote:
> Just to complicate things, you could actually implement chaining, but
> it is more work.
>
> 1) Write a custom NavigationHandler
> 2) create some kind of "magic" syntax for chaining
> 3) Check in the NavigationHandler for the specified syntax
> 4) Invoke additional actions from the custom navigation handler
>
> Something like this should work (BTW - I didn't check that this
> compiles, I typed it from memory):
>
> public class ChainingNavigationHandler
>  extends NavigationHandlerImpl
> {
>  public final static String CHAIN_PREFIX = "chain-action:";
>
>  @Override
>  public void handleNavigation(FacesContext context, String fromAction,
>    String outcome)
>  {
>    if (outcome != null && outcome.startsWith(CHAIN_PREFIX))
>    {
>      String newAction = "#{" + 
> outcome.substring(CHAIN_PREFIX.length()) + "}";
>      MethodBinding mb =
> context.getApplication().createMethodBinding(newAction);
>      Object result = mb.invoke();
>      outcome = (result == null) ? null : result.toString();
>      fromAction = newAction;
>    }
>    super.handleNavigation(context, fromAction, outcome);
>  }
> }
>
> Then, from your action:
> return ChainingNavigationHandler.CHAIN_PREFIX + "myBean.nextAction";
>
>
> -Andrew
>
> On 11/30/06, Jeff Bischoff <jb...@klkurz.com> wrote:
>> Yes, do what Andrew said. The code pattern will look something like:
>>
>> public String firstAction() {
>>    MyBean secondBean = getMySecondBean();
>>    if(someCondition) {
>>      return secondBean.secondAction();
>>    }
>> }
>>
>> Regards,
>>
>> Jeff Bischoff
>> Kenneth L Kurz & Associates, Inc.
>>
>> Andrew Robinson wrote:
>> > Just call the action method of another bean from the action method
>> > invoked by the UICommand componen.
>> >
>> > On 11/29/06, Amit Kushwaha <bl...@googlemail.com> wrote:
>> >> Hi.
>> >>
>> >> Is there a action chaining like functionality for managed beans?  For
>> >> ex, I'd like the result of a managed bean invoke a method in another
>> >> managed bean which takes the user to a view.
>> >>
>> >> I have tried, to-action-id but that didn't work. Am dealing with 
>> pre JSF
>> >> 1.2.
>> >>
>> >> TIA.
>> >>
>> >> Regards.
>> >>
>> >> Amit
>> >>
>> >>
>> >>
>> >
>> >
>> >
>>
>>
>>
>


Re: Action chaining

Posted by Andrew Robinson <an...@gmail.com>.
Just to complicate things, you could actually implement chaining, but
it is more work.

1) Write a custom NavigationHandler
2) create some kind of "magic" syntax for chaining
3) Check in the NavigationHandler for the specified syntax
4) Invoke additional actions from the custom navigation handler

Something like this should work (BTW - I didn't check that this
compiles, I typed it from memory):

public class ChainingNavigationHandler
  extends NavigationHandlerImpl
{
  public final static String CHAIN_PREFIX = "chain-action:";

  @Override
  public void handleNavigation(FacesContext context, String fromAction,
    String outcome)
  {
    if (outcome != null && outcome.startsWith(CHAIN_PREFIX))
    {
      String newAction = "#{" + outcome.substring(CHAIN_PREFIX.length()) + "}";
      MethodBinding mb =
context.getApplication().createMethodBinding(newAction);
      Object result = mb.invoke();
      outcome = (result == null) ? null : result.toString();
      fromAction = newAction;
    }
    super.handleNavigation(context, fromAction, outcome);
  }
}

Then, from your action:
return ChainingNavigationHandler.CHAIN_PREFIX + "myBean.nextAction";


-Andrew

On 11/30/06, Jeff Bischoff <jb...@klkurz.com> wrote:
> Yes, do what Andrew said. The code pattern will look something like:
>
> public String firstAction() {
>    MyBean secondBean = getMySecondBean();
>    if(someCondition) {
>      return secondBean.secondAction();
>    }
> }
>
> Regards,
>
> Jeff Bischoff
> Kenneth L Kurz & Associates, Inc.
>
> Andrew Robinson wrote:
> > Just call the action method of another bean from the action method
> > invoked by the UICommand componen.
> >
> > On 11/29/06, Amit Kushwaha <bl...@googlemail.com> wrote:
> >> Hi.
> >>
> >> Is there a action chaining like functionality for managed beans?  For
> >> ex, I'd like the result of a managed bean invoke a method in another
> >> managed bean which takes the user to a view.
> >>
> >> I have tried, to-action-id but that didn't work. Am dealing with pre JSF
> >> 1.2.
> >>
> >> TIA.
> >>
> >> Regards.
> >>
> >> Amit
> >>
> >>
> >>
> >
> >
> >
>
>
>

Re: Action chaining

Posted by Jeff Bischoff <jb...@klkurz.com>.
Yes, do what Andrew said. The code pattern will look something like:

public String firstAction() {
   MyBean secondBean = getMySecondBean();
   if(someCondition) {
     return secondBean.secondAction();
   }
}

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Andrew Robinson wrote:
> Just call the action method of another bean from the action method
> invoked by the UICommand componen.
> 
> On 11/29/06, Amit Kushwaha <bl...@googlemail.com> wrote:
>> Hi.
>>
>> Is there a action chaining like functionality for managed beans?  For
>> ex, I'd like the result of a managed bean invoke a method in another
>> managed bean which takes the user to a view.
>>
>> I have tried, to-action-id but that didn't work. Am dealing with pre JSF
>> 1.2.
>>
>> TIA.
>>
>> Regards.
>>
>> Amit
>>
>>
>>
> 
> 
>