I actually mistyped; I greatly prefer option A, not B, below. So Martin, your suggestion sounds good.

My JavaScript is great, but my JQuery is not so hot. I added your code and... my AjaxSubmitLink now no longer performs an upload at all. Here's the script that's being added to the page:

   <script type="text/javascript" >
   /*<![CDATA[*/
   Wicket.Event.add(window, "domready", function(event) {
   new Wicket.WUPB('id4', 'id5', 'id6',
   
'../resource/org.apache.wicket.Application/org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar?upload=5',
   'id3', 'Upload starting...');;
   
Wicket.Ajax.ajax({"u":"./com.example.ExamplePage?5-4.IBehaviorListener.0-form-go","m":"POST","c":"id8","f":"id4","mp":true,"sc":"go","bsh":[function(attrs,
   jqXHR, settings){$('#'id7).empty();}],"e":"click"});;
   ;});
   /*]]>*/
   </script>


Here's what my button (id8) HTML looks like:

            <button class="pure-button" type="button" id="id8">
              <i class="fa fa-cloud-upload"></i>
              Go!
            </button>
          </div>

id7 is indeed the ID of the feedback <div> (which starts out empty anyway).

Garret

P.S. A few IDs and strings were changed here and there to generalize the code.

On 11/13/2014 7:50 PM, Martin Grigorov wrote:
Hi,

On Thu, Nov 13, 2014 at 11:36 PM, Garret Wilson <gar...@globalmentor.com>
wrote:

Hi, all. I've done a bit of searching to find the answer, and nothing
quite seemed to fit, or was obsolete, or was deprecated, or was vague. So
I'll ask on the list.

I have a page that uses a multipart form submit. It allows the user to
select a file, and has an AjaxSubmitLink with the label "Go" that 1)
uploads a large file and then 2) does something that takes a long time.
When finished, it calls info("finished!") to show a success message in the
feedback area.

So let's suppose that the user selects a file and selects "Go". After the
file is uploaded, the processing takes place and the feedback area says
"finished!" Perfect.

Question: If the user selects /another/ file and selects "Go" /again/, how
can I immediately remove the "finished!" message, either A) as soon as the
user selects "Go" or B) as soon as the file finishes uploading but before
processeing starts? (I greatly prefer option B.)

How is your JavaScript ?

For A)
AjaxSubmitLink(...) {
   @Override protected void updateAjaxAttributes(attrs) {
     attrs.getAjaxCallListeners().add(new
AjaxCallListener().onBeforeSend("$('#'"+feedback.getMarkupId()+").empty();"))
   }
}

For B)
I can imagine this only with WebSockets.
With HTTP 1.1 the Ajax response should be complete to be flushed to the
client by Wicket.
With WebSockets you can push data at any point of the request processing.
If you choose to use Wicket Native WebSockets then see
WebSocketRequestHandler#push(String). You can push JSON that tells the
client side WebSocket listener at the browser to do the same as the JS in A)


Thanks,

Garret


Reply via email to