You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by avchavan <av...@yahoo.co.in> on 2015/01/13 07:45:05 UTC

Wicket 6.13 link onclick behavior not working with ajax onclick row select

Hi,
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. 
When i right click on the link and open it in another tab the call to
onClick method of link happens successfully as expected.
Can anyone point me in the correct direction to get this sorted?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-6-13-link-onclick-behavior-not-working-with-ajax-onclick-row-select-tp4668995.html
Sent from the Users forum 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 6.13 link onclick behavior not working with ajax onclick row select

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

The 'click' event propagates from the <a> (the link) to the <tr> (the row).
This is normal behavior in JavaScript.
You need to add something like: <a onclick="event.stopPropagation()"
wicket:id="myLink">...</a>

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jan 13, 2015 at 7:45 AM, avchavan <av...@yahoo.co.in>
wrote:

> Hi,
> 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.
> When i right click on the link and open it in another tab the call to
> onClick method of link happens successfully as expected.
> Can anyone point me in the correct direction to get this sorted?
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-6-13-link-onclick-behavior-not-working-with-ajax-onclick-row-select-tp4668995.html
> Sent from the Users forum 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 6.13 link onclick behavior not working with ajax onclick row select

Posted by avchavan <av...@yahoo.co.in>.
Thanks.
Worked for me :)

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-6-13-link-onclick-behavior-not-working-with-ajax-onclick-row-select-tp4668995p4669001.html
Sent from the Users forum 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