org.apache.tapestry.callback
Class ExternalCallback

java.lang.Object
  extended by org.apache.tapestry.callback.ExternalCallback
All Implemented Interfaces:
Serializable, ICallback

public class ExternalCallback
extends Object
implements ICallback

A callback for returning to an IExternalPage.

Example usage of ExternalCallback:

The External page ensure a user is authenticated in the IPage.validate(IRequestCycle) method. If the user is not authenticated, they are redirected to the Login page, after setting a callback in the Login page.

The Login page formSubmit() IActionListener authenticates the user and then invokes ICallback.performCallback(IRequestCycle) to the External page.

  public class External extends BasePage implements IExternalPage {
 
      private Integer _itemId;

      public void validate(IRequestCycle cycle) throws RequestCycleException {            
          Visit visit = (Visit) getVisit();
      
          if (!visit.isAuthenticated()) {
              Login login = (Login) cycle.getPage("Login");

              login.setCallback
                  (new ExternalCallback(this, cycle.getServiceParameters()));
              
              throw new PageRedirectException(login);
          }            
      }
 
      public void activateExternalPage(Object[] params, IRequestCycle cycle)
              throws RequestCycleException {            
          _itemId = (Integer) params[0];
      }
  }

  public Login extends BasePage {
 
      private ICallback _callback;

      public void setCallback(ICallback _callback) {
          _callback = callback;
      }

      public void formSubmit(IRequestCycle cycle) {
          // Authentication code
          ..
   
          Visit visit = (Visit) getVisit();

          visit.setAuthenticated(true);
  
          if (_callback != null) {
              _callback.performCallback(cycle);
          }
      }
  }    
  

Since:
2.3
Version:
$Id: ExternalCallback.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Malcolm Edgar
See Also:
IExternalPage, ExternalService, Serialized Form

Constructor Summary
ExternalCallback(IExternalPage page, Object[] parameters)
          Creates a new ExternalCallback for the page.
ExternalCallback(String pageName, Object[] parameters)
          Creates a new ExternalCallback for the named IExternalPage.
 
Method Summary
 void performCallback(IRequestCycle cycle)
          Invokes IRequestCycle.setPage(String) to select the previously identified IExternalPage as the response page and activates the page by invoking activateExternalPage() with the callback parameters and request cycle.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExternalCallback

public ExternalCallback(String pageName,
                        Object[] parameters)
Creates a new ExternalCallback for the named IExternalPage. The parameters (which may be null) is retained, not copied.


ExternalCallback

public ExternalCallback(IExternalPage page,
                        Object[] parameters)
Creates a new ExternalCallback for the page. The parameters (which may be null) is retained, not copied.

Method Detail

performCallback

public void performCallback(IRequestCycle cycle)
Invokes IRequestCycle.setPage(String) to select the previously identified IExternalPage as the response page and activates the page by invoking activateExternalPage() with the callback parameters and request cycle.

Specified by:
performCallback in interface ICallback

toString

public String toString()
Overrides:
toString in class Object