Ok guys, it worked , I used the AttributeModifier. The thing is, why there's is that renderOnEventJavascript? This should be a method attached maybe to the domready event... Do you think that is worth submiting a patch? Or this is the correct behavior? (IMHO this isn't all right). Anyway, problem solved, thank you all!
2010/10/13 Michael O'Cleirigh <michael.ocleir...@rivulet.ca>: > Hello, > > You can use: > > textfield.add (new AttributeModifier ("onkeydown", true, "if > (window.event.altKey){if (window.event.keyCode == > 80){document.getElementById('" + link.getMarkupId() + > "').onclick();}}"); > > If you do this within the Component.onInitialize() you will have the true > markupid of the link available. > > If you wanted to get rid of the link altogether you could just attach an > ajax event directly to the text field like: > > textfield.add (new AjaxEventBehavior ("onkeydown") { > > �...@override > protected void onEvent(final AjaxRequestTarget target) { > // do your serverside logic > } > > �...@override > protected CharSequence getPreconditionScript() { > // if this evaluates to true in the browser then the event will be > executed. > return "return window.event.altKey && window.event.keyCode == 80;"; > } > > }): > > This is untested but I think it should work, > > Regards, > > Mike > >> I searched all over the internet and it seems that no one uses this >> method. The thing is that I am almost thinking that this is a bug, >> because it's really not logic to me. What I am trying to do: I am >> creating a panel that I will use in a lot of forms, and I want to >> attach some javascript code to my onKeyDown HTML event of this >> TextField, so my code looks like this: >> >> >> >> container.getHeaderResponse().renderOnEventJavascript("document.getElementById('"+txtCliente.getMarkupId()+"')", >> "onKeyDown", "if (window.event.altKey){if (window.event.keyCode == >> 80){document.getElementById('" + link.getMarkupId() + >> "').onclick();}}"); >> >> It's basically this: When user press Ctrl+P while TextField focused, >> it will click on a link, that is another component of my panel. When >> it renders the Javascript there's a problem: It render on the HEAD >> section of HTML, referencing the TextField with a variable (with a >> random name), but BEFORE the TextField was rendered on the HTML. The >> result of this is that Firefox and Chrome gives an error , saying that >> the component doesn't exist, and, in fact it doesn't, because the DOM >> still didn't load! So, probably I am doing this wrong, does anyone can >> help me with that? And what's the reason of this function >> renderOnEventJavascript if it renders on the head? It will always give >> an error message saying the component is null, am I right? I am using >> the latest release of 1.4 series. Thank you very much guys! >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org