views:

13

answers:

1

Hi everyone! I have next situation: I open ModalWindow and show in it several Panels by clicking on button - and I need to attach some JavaScript on viewing concrete Panel. How can I do it?

I tried to add Behavior on my Panel:

add(new AbstractBehavior() {
            private static final long serialVersionUID = 1L;

            @Override
            public void renderHead(IHeaderResponse response) {
                String js = "function myFunction(parameter) {  alert('asdasd1'); }";
                response.renderJavascript(js, null);
                response.renderOnDomReadyJavascript("$(document).ready(function() { alert('test2'); myFunction("+paramsFromWicket+") }); ");
            }
        });

but it doesn't work :(

A: 

My bad, I found solution. I had to use AbstractAjaxBehavior

add(new AbstractAjaxBehavior() {
            private static final long serialVersionUID = 1L;
            @Override
            public void onRequest() {
            }
            @Override
            public void renderHead(IHeaderResponse response) {
                String js = "function myFunction(param) { alert('Hello World'); } $(document).ready(function() { myFunction(" paramFromWicket + "); });";
                response.renderOnDomReadyJavascript(js);
            }
        });
hunterman