sina
sina

Reputation: 1829

Wicket AjaxLink generates no JavaScript

I started experimenting with Wicket AJAX functionality and wanted to implement an AjaxLink.

This is the associated markup/java-code:

<a wicket:id="testlink"></a>
---
AjaxLink<Component> link = new AjaxLink<Component>("testlink") {
    @Override
    public void onClick(AjaxRequestTarget target) {
        System.out.println("called");
    }
};
add(link);

But the onClick-method is never called, I guess because the generated HTML looks like this:

<a wicket:id="testlink" id="testlink7" href="javascript:;"></a>

Any ideas on what I am doing wrong?

Upvotes: 1

Views: 1230

Answers (3)

Malk Yeh
Malk Yeh

Reputation: 1

In my situation, I removed the following onload on body tag and the AjaxLink onclick function worked again.

<body onLoad="MM_preloadImages('template-image/searchbto.png');">

Upvotes: 0

sina
sina

Reputation: 1829

Thanks Robert for clarifying the ajax mechanisms of Wicket 6 - I'm rather new to this topic and the insights you gave me helped solve the problem.

Actually it was caused by some jQuery inconsistency I still haven't fully untangled, apparently coworkers used different jQuery-versions within different of our Wicket modules and somehow Wicket used not the one it was shipped with but a wrong one when trying to attach the event listener to the component.

When removing the unneccessary old jQuery libraries Wicket started to work fine - now I just have to get the components depending on the other jQuery libraries working again, but thats a different story :)

Upvotes: 0

Robert Niestroj
Robert Niestroj

Reputation: 16131

This href="javascript:;" works because Wicket 6 uses JavaScript Event registration. Look at your webpage in some browser dev tool like in firefox. Point the inspector to the link and read it's id, then go the the head section and expand one of the <script type= text/javascript></script> tags. There you should find the id of the link and see that there is an line where a click event is attached to the id of the link. The URL there is executed when you click the link.

Screenshot from Firefox Dev Tools

Upvotes: 2

Related Questions