Wicket 6.13 link onclick 行为不适用于 ajax onclick 行 select
Wicket 6.13 link onclick behavior not working with ajax onclick row select
我最近从 Wicket 1.5.11 升级到 Wicket 6.13
升级后,我面临 link.
的 onclick 行为问题
我们有一个可点击的行,其中包含几列(其中一列是 link 到新页面)。
现在,如果我们点击 link 然后我们被带到新页面,我们点击该行(除了 link)该行被选中(使用 Ajax 调用)。
这在 Wicket 1.5.11 上运行良好,我在 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));
}
}
填充方法:
@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 而不是 link 的 onClick 方法时,将调用行的 Ajax 行为的 onclick 事件。
谁能指出正确的方向来解决这个问题?
更新:当我右键单击 link 并在另一个选项卡中打开它时,对 link 的 onClick 方法的调用按预期成功进行。
我找到了解决方案。
在代码中添加了以下行:
myLink.add(new AttributeAppender(
"onclick", new Model("if(event.stopPropagation) { "+
"event.stopPropagation();"+
"} else { "+"event.cancelBubble = true;"
+"}"), ";"));
link onclick 事件被传播到该行的 onclick 事件,因此它以这种方式运行。
我刚 运行 遇到了同样的问题。由于我的应用程序不支持低于 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();"), ";");
}
}
我有同样的症状:Ajax 从 Wicket 1.4 直接迁移到 Wicket 7.9 后,行为不起作用。
就我而言,原因是:jquery javascript 无法加载源。他们被禁止提供服务。
我的应用程序使用了 class AuthStrategy,它有一个方法:
@Override
public boolean isResourceAuthorized(IResource arg0, PageParameters arg1) {
return false;
}
因此,无法加载 jquery js 源代码。将 return 更改为 True 解决了问题。
似乎通过该方法传递的唯一资源是那些 jquery javascripts.
我最近从 Wicket 1.5.11 升级到 Wicket 6.13 升级后,我面临 link.
的 onclick 行为问题我们有一个可点击的行,其中包含几列(其中一列是 link 到新页面)。 现在,如果我们点击 link 然后我们被带到新页面,我们点击该行(除了 link)该行被选中(使用 Ajax 调用)。
这在 Wicket 1.5.11 上运行良好,我在 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));
}
}
填充方法:
@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 而不是 link 的 onClick 方法时,将调用行的 Ajax 行为的 onclick 事件。 谁能指出正确的方向来解决这个问题?
更新:当我右键单击 link 并在另一个选项卡中打开它时,对 link 的 onClick 方法的调用按预期成功进行。
我找到了解决方案。 在代码中添加了以下行:
myLink.add(new AttributeAppender(
"onclick", new Model("if(event.stopPropagation) { "+
"event.stopPropagation();"+
"} else { "+"event.cancelBubble = true;"
+"}"), ";"));
link onclick 事件被传播到该行的 onclick 事件,因此它以这种方式运行。
我刚 运行 遇到了同样的问题。由于我的应用程序不支持低于 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();"), ";");
}
}
我有同样的症状:Ajax 从 Wicket 1.4 直接迁移到 Wicket 7.9 后,行为不起作用。
就我而言,原因是:jquery javascript 无法加载源。他们被禁止提供服务。
我的应用程序使用了 class AuthStrategy,它有一个方法:
@Override
public boolean isResourceAuthorized(IResource arg0, PageParameters arg1) {
return false;
}
因此,无法加载 jquery js 源代码。将 return 更改为 True 解决了问题。
似乎通过该方法传递的唯一资源是那些 jquery javascripts.