Hi Nishant,
you should use
component.setOutputMarkupId(true);
this tells wicket to generate a unique markup id. You can refer to the
generated id with
component.getMerkupId();
later.
If you want to add some javascript to your page, you may use two different
tricks:
A: Ajax-related
If you have an AjaxTrigger (e.g. an AjaxLink) do the following
AjaxLink() {
onClick(AjaxRequestTarget target) {
target.appendJavaScript(<put your javascript here>);
// e.g. doSomethingWithDomelementWithId('"+
component.getmarkupId()+ "');
}
}
B. during page creation
If you want to bind some javascript during page creation/HTML render time try
this
Class MyPanel extends Panel {
...
@Override
public void renderHead(HtmlHeaderContainer container) {
container.getHeaderResponse().renderJavascriptReference(<add a resource
reference to your js library here>);
container.getHeaderResponse().renderOnDomReadyJavascript("soSomethingWith('" +
getMarkupId() + "');");
}
}
And: Please have a look at the javadocs.
Stefan
-----Ursprüngliche Nachricht-----
Von: Nishant Neeraj [mailto:[email protected]]
Gesendet: Dienstag, 6. April 2010 18:02
An: [email protected]
Betreff: Re: Best Practices for Using JavaScript With Wicket
Thanks Jeremy.
I had been using component.setMarkupId(..); which is not recommended... so I
was wondering what is the standard.
I need to get hands-on JS-Wicket integration, so I was looking for a good
organized documentation/resource (other than WIA).
> So, what's the objection to using it?
:) Nothing against wiQuery and I, probably, will go with wiQuery... I was
worried if I can integrate various the plug-ins available like jNice (
http://www.whitespace-creative.com/jquery/jNice/) and likes.
Thanks for pointers.
Nishant
On Tue, Apr 6, 2010 at 4:26 AM, Jeremy Thomerson
<[email protected]>wrote:
> >
> > I am finding it very cumbersome to integrate JavaScript/JS-library. Can
> > someone point to (or probably write a blog-post on :->) the best
> practices
> > of integrating JS/JS-library with Wicket.
> >
>
> Wicket is pretty flexible in that you can integrate your JS a dozen
> different ways. jQuery is especially easy to integrate with because the
> programming model matches Wicket's fairly nicely. The primary thing is
> that
> if you want to use element IDs to tie in to jQuery, you'll need to do this
> from behaviors in your java code so that you get the correct ID.
>
>
> >
> > I am using JQuery but I would like to know the best approach without
> using
> > WiQuery or jWicket. (Unless, I have to write my own jWicket to get this
> > done.)
> >
>
> I'm not sure I understand. wiQuery has been fairly well recognized as a
> very nice Wicket/jQuery integration. It has active development and a
> helpful mailing list. So, what's the objection to using it? I'm not
> saying
> that you can't have an objection, I just wonder what it is. It's an open
> source project, so you can use it as a base and add your own functionality
> as needed (hopefully contributing back).
>
> Even if you don't want to use it, you can see some of the things they are
> doing with it - it has some very nice features, including mergin all the JS
> header contributions into a common (single) resource file.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]