You can try using Uploadify from code.google.com/p/jqwicket/, which lets you
put event handlers on successful completion.  You need to write a separate
servlet to handle upload though, but it's quite straightforward. One small
trick is overriding getEventHandler() so you can pass the javascript
generated to call the behaviour from other javascript components. The
example below uses a uuid to communicate between the upload form and the
servlet.


            // ajax behaviour added to parent as bogus "onNever" event
handler
            OnComplete onComplete = new OnComplete("onNever", ip, uuid);
            wmc.add(onComplete);
            wmc.add(new UploadifyWebMarkupContainer("upload", new
UploadifyOptions().auto(true).multi(false).scriptAccess("always").
                    script(getRequest().getRelativePathPrefixToContextRoot()
+ "upload?uuid=" + uuid).onCompleteEvent(onComplete.getEventHandler())));

...

    /**
     * AJAX behaviour fired when upload is ready
     */
    public class OnComplete extends AjaxEventBehavior {

        Picture picture;
        String uuid;

        public OnComplete(String event, Picture picture, String uuid) {
            super(event);
            this.picture = picture;
            this.uuid = uuid;
        }

        public String getUuid() {
            return uuid;
        }

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            // servlet stores uploaded image
            byte[] bytes = UploadifyServlet.getAndRemoveBytes(uuid);
            if (bytes != null) {
                PhotoUtil.handleImageUpload(bytes, picture);
            }
            target.addComponent(getComponent().getParent().getParent());
        }

        // need to be public
        @Override
        public CharSequence getEventHandler() {
            return super.getEventHandler();
        }
    }




On Sat, Aug 27, 2011 at 4:40 AM, Chris Colman
<chr...@stepaheadsoftware.com>wrote:

> Is it possible to open a modal window after file upload completion.
>
> Even though I'm using the AJAX file upload which shows the progress bar
> the submit handler doesn't contain a 'target' parameter required to
> bring up a modal.
>
> protected void onSubmit()
> {
>            final FileUpload upload = fileUploadField.getFileUpload();
>            if (upload != null)
>            {
>                         // Create a new file
>                        .....
>            }
>
> The reason is that I do some processing of the file after uploading and
> I want to display to the user the results of that processing. Any ideas?
>
>

Reply via email to