1

I have spent several hours, maybe days stucked on a very weird problem :(

I am creating an application that is based on the Wicket solution. It works perfectly in IE9,IE10, Chrome and FF. Strange is, that i have tested it in IE8 too and it works in 99% of cases (IE instances on different computers + totally identical version of IE8) too. But now the PROBLEM.

PROBLEM: I am creating dynamic content over AjaxLink button. After clicking the button the WebMarkupContainer model is changed and WebMarkupContainer is refreshed (based on Ajax, so the page isnt reloaded complete, but only the container is).

Every item in the container has added AjaxFormComponentUpdatingBehavior. In onComponentTag method, i add tag.put("onchange","some jsFunctionCalling....");. The problem is, that after clicking on the item, no event is invoked. I have tried add the onchange listener over .add(new AttributeModifier.....), but the result is still same. As i have said, i tried the same code in the same version of IE on another PC and it works perfectly. Interesting is, that after refreh of the page everything work perfect, until new item to WebMarkupContainer is added. After that no item listeners work until the page is refreshed again.

One of the latest idea, that i got is, that problem isn't in the code, but in the settings of IE (maybe security). Have anybody any idea? What setting could be set different and cause these problems? Is there any settings on Wicket site, that can solved this? Is there some setting that can blocked registration of these listeners to DOM, if they are added dynamically over ajax?

4

3 回答 3

1

我没有尝试过,但恕我直言,您可以尝试三个选项:

  1. 与其自己添加“onchange”,不如OnChangeAjaxBehavior在检票口中添加并使所有工作。缺点是每个事件的服务器往返。
  2. 添加数据属性 ( AttributeModifier.append("data-param1", "foobar")) 以将您的参数推送到 html 并ajaxRequestTarget.appendJavaScript("attachOnChangeHandler()"); 在 AjaxLink 上的单击事件之后调用。attachOnChangeHandler()应该是您的 js 函数,用于将 onchange 处理程序添加到需要它的每个项目。通过数据属性,您可以访问您的参数。
  3. 从 Wicket 6开始:为了避免与 Wicket 混用太多 js,您可以订阅全局 AJAX 事件之一。您的解决方案与 2 中的解决方案几乎相同。只需在 js 中为“/ajax/call/success”添加一个侦听器(通过检查 id 查看调用是否与您的组件相关)并在那里添加 onchange 处理程序。这是恕我直言,无需将自定义 js 与 Wicket 混合的最佳解决方案。

@peterchon 提供的解决方案(在 DOM 中附加的事件处理程序高于将被 wicket 替换的元素)适用于所有其他情况,但您有“onchange”,它仅适用于输入、文本区域和选择元素。

顺便说一句,刷新后页面正在“工作”,因为整个页面都被渲染并且浏览器可以正确附加处理程序。

于 2013-11-23T11:25:29.633 回答
0

您尝试使用非检票口 JavaScript/Ajax 方式来实现某些目标。这很好,但也使它非常混乱。

请查看这篇关于将参数从 JavaScript 传递到检票口的精彩文章,反之亦然。我认为它会满足您的需求。

http://wickedsource.org/2013/01/07/rolling-your-own-ajax-behavior-with-wicket/

于 2013-11-26T14:02:40.193 回答
0

你可以试试这个方法:

/* this will catpure the target that triggered the event */
function getEventTarget( e ) {
  e = e || window.event;
  return e.target || e.srcElement;
}

function doSomething( e ) {
  var that = getEventTarget( e );
  if( that.tagName.toLowerCase() === 'a' ) { // specify the target, in this cas <a>
    // Do something
  }
}

parentElement.onclick = doSomething;

该脚本基本上将捕获任何事件,然后将目标变量传递给将执行某些操作的函数。

希望这对你有用。

于 2013-11-21T19:28:39.967 回答