Anton Veretennikov wrote:
>
> For example I use this markup:
>
> <script wicket:id="focusScript"></script>
>
> and associate it with simple class:
>
> public class FocusScript extends Label {
>
> public FocusScript(String id, String focusFieldMarkupId, boolean
> selectAll) {
> super(id, getFocusScript(focusFieldMarkupId, selectAll));
> setEscapeModelStrings(false);
> }
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> tag.put("language", "javascript");
> tag.put("type", "text/javascript");
> super.onComponentTag(tag);
> }
>
> @Override
> protected void onComponentTagBody(MarkupStream markupStream,
> ComponentTag openTag) {
> super.onComponentTagBody(markupStream, openTag);
> checkComponentTag(openTag, "script");
> }
>
> public static String getFocusScript(String focusFieldMarkupId,
> boolean selectAll) {
> return "document.getElementById('" + focusFieldMarkupId +
> "').focus();" +
> (selectAll?("document.getElementById('" +
> focusFieldMarkupId + "').select()"):"");
> }
>
> }
>
>
Thanks Igor and Anton. That approach works. One thing to remember is to call
"setEscapeModelStrings(false)" to insert string "<script> ....</script>" as
it is, as Anton pointed out.
--
View this message in context:
http://www.nabble.com/how-to-inject-arbitrary-javascript-code-to-a-component-markup--tp25833726p25837324.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org