2015-01-12 65 views
0

我最近已從Wicket 1.5.11升級到Wicket 6.13 升級後,我面臨的問題與鏈接的onclick行爲。Wicket 6.13鏈接onclick行爲不工作與ajax onclick行選擇

我們有一個可點擊的行,其中包含少量列(其中之一是指向新頁面的鏈接)。 現在,如果我們點擊鏈接,然後我們被帶到新頁面,我們點擊行(除了鏈接)該行被選中(使用Ajax調用)。

這是工作的罰款與檢票1.5.11,我跟檢票6.13面臨的問題

Link類:

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)); 
} 
} 

填充方法:

@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); 
     } 
    }); 
} 

當我嘗試點擊在鏈接的LINK而不是onClick方法上,行的AjaxBehavior的onclick事件被調用。 任何人都可以指出我正確的方向來得到這個排序嗎?

更新:當我右鍵單擊該鏈接並在另一個選項卡中打開鏈接的onClick方法的調用發生成功按預期。

+0

爲什麼6.13而不是最新的6.18? –

+0

@ martin-g客戶要求:/ –

回答

2

我找到了解決方案。 增加了以下行的代碼:

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

鏈路onclick事件被傳播到該行的onclick事件,因此它是在這樣的方式表現。

0

我剛碰到同樣的問題。由於我的應用程序不支持低於9的IE版本(見https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation),我一直在我AttributeAppender簡單:

public class EventStopPropagationAttributeAppender extends AttributeAppender { 

    public EventStopPropagationAttributeAppender() { 
    super("onclick", new Model<String>("event.stopPropagation();"), ";"); 
    } 
} 
0

我有同樣的症狀:阿賈克斯行爲從檢票1.4遷移直接檢票口後7.9沒有工作。

在我的情況下,原因是:jquery javascript源碼coudn't加載。他們被禁止服務。

我的應用程序使用的類AuthStrategy,並且它有一個方法:

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

所以,jQuery的JS源不可能是加載。更改返回到解決了這個問題。

似乎通過該方法傳遞的唯一資源是那些jquery javascripts。