Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Tapestry 5 Mixin for a loading spinner with spin.js
package com.yourapp.mixins;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ClientElement;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
//Put the spin.min.js wherever on the context and point to it here
library = {
public class LoadingSpinner {
@Parameter(defaultPrefix = BindingConstants.LITERAL)
private boolean closeSpinner;
private JavaScriptSupport javaScriptSupport;
private ClientElement clientElement;
public void afterRender() {
if ( closeSpinner) {
} else {
"$('#%s').click(function(e) { "
+ "new Spinner().spin($('<div />', { class: 'loader-wrapper'}).appendTo('body')[0]); "
+ "});", clientElement.getClientId());
<html xmlns:t=""
This example shows using the spinner mixin with a Tapestry-jQuery ajax dialog.
But it is just as easy to use in any other situation when a zone is rendered
(i.e. any actionlink, eventlink, form submit, etc. that are bound to a zone).
<!-- when this is clicked, a spinner object will be added to the DOM -->
<t:jquery.dialogajaxlink dialog="myDialog" t:id="myDialogLink" class="btn btn-info" t:mixins="LoadingSpinner" zone="myDialogZone">
Long operation
<t:jquery.dialog t:clientId="myDialog" title="My Dialog">
<t:zone t:id="mtDialogZone">
<!-- when this zone renders it will kill the spinner object -->
<t:any t:mixins="LoadingSpinner" t:closeSpinner="true" />
Wow! This took a very long time... lucky we had that spinner to make time go by faster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.