Looks fine to me. Does you filename have an extension (e.g. ".txt")?

Sven

On Fri, 2010-12-03 at 13:42 -0800, val360 wrote:
> final AJAXDownload download = new AJAXDownload() {
>   @Override
>   protected IResourceStream getResourceStream() {
>       return new FileResourceStream(theDatabase.getFile());
>   }
> 
>   @Override
>   protected String getFileName() {
>       return theDatabase.getFile().getAbsoluteFile().getName();  //FIX!!! the
> filename gets .html appended to it.
>   }
> };
> add(download);
> 
> add( new AjaxLink("download") {
>       public void onClick( AjaxRequestTarget target ) {
>               if( theDatabase.isOpen() ) {
>                       target.appendJavascript( "alert('The database is open, 
> close or pause the
> db first.');" );
>               } else {
>                       download.initiate( target );
>               }
>       }
> });
> 
> And this class is unchanged:
> 
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.behavior.AbstractAjaxBehavior;
> import
> org.apache.wicket.request.target.resource.ResourceStreamRequestTarget;
> import org.apache.wicket.util.resource.IResourceStream;
> 
> /**
>  * @author Sven Meier
>  * @author Ernesto Reinaldo Barreiro (reier...@gmail.com)
>  */
> public abstract class AJAXDownload extends AbstractAjaxBehavior
> {
>       /**
>        * Call this method to initiate the download.
>        */
>       public void initiate(AjaxRequestTarget target)
>       {
>               CharSequence url = getCallbackUrl();
> 
>               target.appendJavascript("window.location.href='" + url + "'");
>       }
> 
>       public void onRequest()
>       {
>               getComponent().getRequestCycle().setRequestTarget(
>                               new 
> ResourceStreamRequestTarget(getResourceStream(), getFileName()));
>       }
>       
>       /**
>        * @see ResourceStreamRequestTarget#getFileName()
>        */
>       protected String getFileName()
>       {
>               return null;
>       }
> 
>       /**
>        * Hook method providing the actual resource stream.
>        */
>       protected abstract IResourceStream getResourceStream();
> }



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to