You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mathias Nilsson <wi...@gmail.com> on 2009/07/04 19:25:14 UTC

Wicket and javascript

Hi,

I know there has been some topics on this but I need some pointers on how to
manage this.

I have struggled with the uploadProgressBar for some time but it fails for
all browser. I've decided to create my own upload with progressbar.
It's a html form that post to an IFrame. On post I upload to a servlet. I
can do ajax callbacks to the servlet to see the upload status.

What I want is to when the upload is finished call back to wicket so I can
refresh the file list via ajax. Is this possible? Any pointers?

Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
Thanks!

That did the trick. 
-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24343230.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
yes thanks alot. 

Beacuse I didn't have any other wicket ajax the lib was not included. I just
added a 
super.renderHead(response); and it worked.

Thanks
-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24345756.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Wicket and javascript

Posted by Jeremy Thomerson <je...@wickettraining.com>.
I didn't check it for 100% functionality - I was showing you how the
pieces fit together.  Now you know how to get the URL for the
callback, how to get the callback to work, etc.  Now, look at it and
see what it renders and see if it's correct.

I can't help anyway without knowing what JS error you got.

--
Jeremy Thomerson
http://www.wickettraining.com




On Sun, Jul 5, 2009 at 12:59 PM, Mathias
Nilsson<wi...@gmail.com> wrote:
>
> Nope I get an javascript error when trying this.
>
>
> --
> View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24345368.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
Nope I get an javascript error when trying this.


-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24345368.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Wicket and javascript

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Here, I think this should work:

Pastebin link in case the formatting gets messed up in email:
http://pastebin.com/f6ef575c3

public ExamplePage() {
  IModel<? extends List<? extends String>> model = getSomeModel();
  final ListView<String> lv = new ListView<String>("listview", model) {
       @Override
       protected void populateItem(ListItem<String> item) {
            item.add(new Label("name", item.getModel()));
       }
  };
  final IBehavior repaintBehavior = new AbstractDefaultAjaxBehavior() {
       @Override
       protected void respond(AjaxRequestTarget target) {
            // this repaints the list view
            // this requires your model to always get the most
            // up-to-date list
            target.addComponent(lv);
       }

       @Override
       public void renderHead(IHeaderResponse response) {
            CharSequence callback = getCallbackScript();
            response.renderJavascript("function uploadCompleted() { "
+ callback + "}",
                 "customUploadCompleted");
       }
  };
}


--
Jeremy Thomerson
http://www.wickettraining.com




On Sun, Jul 5, 2009 at 7:57 AM, Mathias
Nilsson<wi...@gmail.com> wrote:
>
> Yes but I will have a WebMarkupContainer with a ListView in that needs to be
> updated via ajax. If my javascript hits the onLinkClicked I won't have any
> AjaxRequestTarget to update the container via ajax.
> --
> View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24342870.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
Yes but I will have a WebMarkupContainer with a ListView in that needs to be
updated via ajax. If my javascript hits the onLinkClicked I won't have any
AjaxRequestTarget to update the container via ajax.
-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24342870.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Wicket and javascript

Posted by Martin Funk <ma...@googlemail.com>.
you are getting closer...

next step is to get the callbackURL to the browser and than pick it up  
by your javascript.
it could be rendered as an attribute using an AttributeModifier.

given that wicket supplies the javaScript method wicketAjaxGet.
If that gets called with the callbackURL the call will hit right  
through to the onLinkClicked()

so far i did that trick with behaviors, but this is an interesting  
approach too.

mf


Am 05.07.2009 um 13:52 schrieb Mathias Nilsson:

>
> Sorry for not getting this totally.
>
> If I do something like this
>
> class Comp extends WebComponent implements ILinkListener{
>
> 		public Comp(String id) {
> 			super(id);
> 			
> 		}
>
> 		public String getCallbackURL(){
> 			return  urlFor( ILinkListener.INTERFACE ).toString();
> 		}
> 		public void onLinkClicked() {
> 			// TODO Auto-generated method stub
> 			
> 		}
>
> 	}
>
> Then how could I update it via AJAX?
> -- 
> View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24342389.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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


Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
Sorry for not getting this totally.

If I do something like this

class Comp extends WebComponent implements ILinkListener{

		public Comp(String id) {
			super(id);
			
		}

		public String getCallbackURL(){
			return  urlFor( ILinkListener.INTERFACE ).toString();
		}
		public void onLinkClicked() {
			// TODO Auto-generated method stub
			
		}

	}

Then how could I update it via AJAX?
-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24342389.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Wicket and javascript

Posted by Igor Vaynberg <ig...@gmail.com>.
first create a url to a component.

this can be done by letting your component implement something like
ilinklistener and calling urlfor(linklistener.interface) on that
component.

once you have the url (which will trigger onclick() of the component)
pass it into some javascript by writing it out into a variable or what
not. then use any 3rd party ajax lib to make the call, or use wicket's
js - have a look in wicket-ajax.js.

-igor

On Sat, Jul 4, 2009 at 4:32 PM, Mathias
Nilsson<wi...@gmail.com> wrote:
>
> Thanks!
>
> I know what to do not just how it could be done
>
> "You have it trigger a Wicket AJAX call to the server on a
> behavior"
>
> How does this work?
> --
> View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24338948.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
Thanks!

I know what to do not just how it could be done

"You have it trigger a Wicket AJAX call to the server on a 
behavior"

How does this work?
-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24338948.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Wicket and javascript

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On the client side you have a JS script that knows when 100% is
reached.  You have it trigger a Wicket AJAX call to the server on a
behavior that repaints your list view.  Then the list view just needs
a proper model that gets an up-to-date list.  Create an abstract
behavior, and there is a method that you can call that gets the JS
callback (IIRC).

--
Jeremy Thomerson
http://www.wickettraining.com




On Sat, Jul 4, 2009 at 2:50 PM, Mathias
Nilsson<wi...@gmail.com> wrote:
>
> Let me be a bit more specific.
>
> A have a plain form, none wicket that posts to an Iframe. In the onsubmit of
> the form I call my ajax function. The action is set to my servlet to receive
> the multipart.
> In the start I setup my ajax and make GET requests to the same servlet for
> updating my progress bar.
>
> When the percentage is 100% I would like to make a call to wicket to update
> a listview of files. I could save the filename in the session when in the
> servlet. is there any way of doing a callback to wicket like this?
> --
> View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24337495.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Wicket and javascript

Posted by Mathias Nilsson <wi...@gmail.com>.
Let me be a bit more specific.

A have a plain form, none wicket that posts to an Iframe. In the onsubmit of
the form I call my ajax function. The action is set to my servlet to receive
the multipart.
In the start I setup my ajax and make GET requests to the same servlet for
updating my progress bar.

When the percentage is 100% I would like to make a call to wicket to update
a listview of files. I could save the filename in the session when in the
servlet. is there any way of doing a callback to wicket like this?
-- 
View this message in context: http://www.nabble.com/Wicket-and-javascript-tp24336438p24337495.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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