001 package com.sptci.echo2;
002
003 import nextapp.echo2.app.ApplicationInstance;
004 import nextapp.echo2.app.event.ActionEvent;
005 import nextapp.echo2.app.event.ActionListener;
006
007 import nextapp.echo2.webcontainer.command.BrowserRedirectCommand;
008
009 /**
010 * An action listener to redirect the client browser to {@link #url}.
011 *
012 * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
013 * @author Rakesh Vidyadharan 2006-12-28
014 * @version $Id: RedirectListener.java 3132 2007-04-24 01:14:11Z rakesh $
015 */
016 public class RedirectListener implements ActionListener
017 {
018 /**
019 * The URL to use to open the browser window.
020 */
021 private final String url;
022
023 /**
024 * Create a new instance of the listener for the specified
025 * {@link #url}.
026 *
027 * @param url The {@link #url} to use.
028 */
029 public RedirectListener( String url )
030 {
031 this.url = url;
032 }
033
034 /**
035 * The action listener implementation. Redirect the client browser to
036 * {@link #url}.
037 *
038 * @see #redirect
039 */
040 public void actionPerformed( ActionEvent event )
041 {
042 redirect();
043 }
044
045 /**
046 * Redirect the client browser to {@link #url}.
047 */
048 protected void redirect()
049 {
050 BrowserRedirectCommand command = new BrowserRedirectCommand( url );
051 ApplicationInstance.getActive().enqueueCommand( command );
052 }
053 }