You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jason Novotny <ja...@gmail.com> on 2014/09/03 22:15:12 UTC

adding wicket generated link to javascript

Hi,

My designer gave me code where HTML is created in javascript as part of 
a jquery dataTable:

<script>
         $(document).ready(function() {
             $('#datatable').dataTable( {
....
$('.clientinvoices .dropholder').html('<div 
class="opener"></div>*<button class="btn" type="reset">Cancel 
Order</button>*');
..
</script>


And I need that button to be a wicket button, is there a way to pass it 
a generated link, etc? What would be the best way to deal with this?

Thanks, Jason


Re: adding wicket generated link to javascript

Posted by Pierre Goupil <go...@gmail.com>.
Good evening,

You can use a Behavior:

- subclass AbstractDefaultAjaxBehavior,
- in the overriden renderHead(final Component component, final
IHeaderResponse response) use template interpolation to pass the URL to the
JS: template.interpolate(variables);
- in the JS, use the Wicket client-side API to do a call to server:
Wicket.Ajax.get({"u":"the/url/to/the/link", "e": "click", "c":"linkId"});  (
https://cwiki.apache.org/confluence/display/WICKET/Wicket+Ajax)
- and lastly, in the Behavior overridden respond(final AjaxRequestTarget
target) do whatever component manipulation you need and play with the
AjaxRequestTarget.

So: in your JS, you have to find the right place to use the
Wicket.Ajax.get() call and you can pass any value from server, not just the
Behavior URL.

Sorry, I was unable to find a link explaining more template interpolation,
but if you like, I can provide you with some code.

HTH,

Pierre




On Wed, Sep 3, 2014 at 10:15 PM, Jason Novotny <ja...@gmail.com>
wrote:

> Hi,
>
> My designer gave me code where HTML is created in javascript as part of a
> jquery dataTable:
>
> <script>
>         $(document).ready(function() {
>             $('#datatable').dataTable( {
> ....
> $('.clientinvoices .dropholder').html('<div class="opener"></div>*<button
> class="btn" type="reset">Cancel Order</button>*');
> ..
> </script>
>
>
> And I need that button to be a wicket button, is there a way to pass it a
> generated link, etc? What would be the best way to deal with this?
>
> Thanks, Jason
>
>


-- 
La vie est source de joie, la mort est source de paix, seule la transition
est difficile.

Re: adding wicket generated link to javascript

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Wed, Sep 3, 2014 at 11:15 PM, Jason Novotny <ja...@gmail.com>
wrote:

> Hi,
>
> My designer gave me code where HTML is created in javascript as part of a
> jquery dataTable:
>
> <script>
>         $(document).ready(function() {
>             $('#datatable').dataTable( {
> ....
> $('.clientinvoices .dropholder').html('<div class="opener"></div>*<button
> class="btn" type="reset">Cancel Order</button>*');
> ..
> </script>
>
>
> And I need that button to be a wicket button, is there a way to pass it a
> generated link, etc? What would be the best way to deal with this?
>

One way is to generate this code with Wicket and make it invisible
(display: none). Then the JS code should just make it visible
(jQuery.show()).

Another way is, as Pierre explained, to use Ajax behavior. In some
#renderHead() method do:
response.render(OnDomReadyHeaderItem.forScript("window.resetUrl =
'"+ajaxBehavior.getCallbackUrl()+"';"))

Later in the JS code you can use jQuery#ajax() or Wicket.Ajax.get() and
make use of window.resetUrl as an endpoint.


>
> Thanks, Jason
>
>