1

I have recently upgraded to Wicket 6.13 from Wicket 1.5.11 After the upgrade i am facing an issue with onclick behavior of a link.

We have a clickable row which contains few columns (one of which is a link to new page). now, if we click on the link then we are taken to new page and we click on the row (apart from the link) the row get selected (using Ajax call).

This was working fine with Wicket 1.5.11, i am facing issues with Wicket 6.13

Link class:

public class MyLink extends Link {

private static final long serialVersionUID = 5808539933400105591L;
private MyRow myRow;

public MyLink(String id, MyRow myRow) {
    super(id);
    this.myRow = myRow;
}

/** {@inheritDoc} */
@Override
public void onClick() {
    //sets the response page where this needs to be redirected.
    this.setResponsePage(new ResponseReadPage(this.myRow));
}
}

Populate method:

@Override
protected void populateItem(final ListItem item) {
    final MyRow myRow = (MyRow) item.getModelObject();
    item.add(new Label("naam", myRow.getName()));
    item.add(new Label("id", myRow.getCode()));

    MyLink myLink = new MyLink("myLink", myRow);
    item.add(myLink);
    final MyRow selectedRow = this.session.getSelectedRow();

    if (selectedRow != null
            && selectedRow.equals(myRow)) {
        this.session.selectedRow(myRow);
        item.add(new AttributeModifier("class", "activeRow"));
        this.selecteditem = item;

        //some business logic
    }

    item.add(new AjaxEventBehavior("onclick") {
        /** {@inheritDoc} */
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            final WebMarkupContainer container = (WebMarkupContainer) MyListView.this.getParent()
                    .getParent().get("myContainer");

            MyListView.this.session.setSelectedRow(myRow);

            if (MyListView.this.currentActiveItem != null) {
                MyListView.this.previousActiveItem = MyListView.this.currentActiveItem;
                MyListView.this.previousActiveItem.add(new AttributeModifier("class", ""));
            }
            item.add(new AttributeModifier("class", "activeRow"));
            MyListView.this.currentActiveItem = item;
            if (MyListView.this.previousActiveItem != null) {
                target.add(MyListView.this.previousActiveItem);
            }

            if (MyListView.this.selecteditem != null
                    && !MyView.this.selecteditem.equals(item)) {
                MyListView.this.selecteditem.add(new AttributeModifier("class", ""));
                target.add(MyListView.this.selecteditem);
            }
            target.add(item);
            target.add(container);
        }
    });
}

When i try to click on the LINK instead of onClick method of the link, the onclick event of AjaxBehavior of row gets called. Can anyone point me in the correct direction to get this sorted?

UPDATE: When i right click on the link and open it in another tab the call to onClick method of link happens successfully as expected.

avinash chavan
  • 729
  • 2
  • 11
  • 27

3 Answers3

2

I found the solution for this. Added the following lines to the code:

myLink.add(new AttributeAppender(
"onclick", new Model("if(event.stopPropagation) { "+
                "event.stopPropagation();"+
                    "} else { "+"event.cancelBubble = true;"
                     +"}"), ";"));

The link onclick event was being propagated to the onclick event for the row, hence it was behaving in such a manner.

Hmahwish
  • 2,222
  • 8
  • 26
  • 45
avinash chavan
  • 729
  • 2
  • 11
  • 27
0

I just ran into the same problem. Since my application does not support IE versions below 9 (see https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation), I kept my AttributeAppender simple:

public class EventStopPropagationAttributeAppender extends AttributeAppender {

  public EventStopPropagationAttributeAppender() {
    super("onclick", new Model<String>("event.stopPropagation();"), ";");
  }
}
bcody
  • 2,489
  • 1
  • 21
  • 21
0

I had the same symptom: Ajax behaviors did not work after migrating from Wicket 1.4 directly to Wicket 7.9.

In my case, the cause was: jquery javascript sources coudn't be loaded. They were being forbidden to be served.

My application used the class AuthStrategy, and it had a method:

@Override
public boolean isResourceAuthorized(IResource arg0, PageParameters arg1) {
    return false;
}

So, the jquery js sources couldnt be loaded. Changing the return to True solved the problem.

The only resources that seems to be passing thru that method are those jquery javascripts.