Dear Wiki user, You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.
The "Tapestry5HowToAddBindingPrefixCycle" page has been changed by DavidRees. http://wiki.apache.org/tapestry/Tapestry5HowToAddBindingPrefixCycle?action=diff&rev1=5&rev2=6 -------------------------------------------------- } }}} - and this also: + And the binding itself: + + Note: that starting with Tapestry 5.2 PageBindings do not appear to be thread safe when running without page pools. So now we store the index in a ThreadLocal which works around this upgrade issue. (The previous version simply used an int for the index instead of a ThreadLocal). + {{{#!java import java.util.List; @@ -92, +95 @@ public class CycleBinding extends AbstractBinding implements PageLifecycleListener{ private final List<Binding> delegates; - private int index = 0; + private ThreadLocal<Integer> index; public CycleBinding(List<Binding> delegates) { this.delegates = delegates; } public Object get() { - Object ret = delegates.get(index).get(); + Object ret = delegates.get(getIndex()).get(); + incrIndex(); - index ++; - if(index>=delegates.size()) index = 0; return ret; } @@ -115, +117 @@ return Object.class; } - public void containingPageDidDetach() { - index=0; + index.remove(); } - public void containingPageDidAttach() {/*not interested*/} + public void containingPageDidAttach() { + index = createThreadLocal(); - + } + - public void containingPageDidLoad() {/*not interested*/} + public void containingPageDidLoad() {} + + public void restoreStateBeforePageAttach() {} + + private ThreadLocal<Integer> createThreadLocal() { + return new ThreadLocal<Integer>() { + @Override + protected Integer initialValue() { + return Integer.valueOf(0); + }; + }; + } + + private int getIndex() { + return index.get().intValue(); + } + + private void incrIndex() { + int i = index.get().intValue() + 1; + if (i >= delegates.size()) { + i = 0; + } + index.set(Integer.valueOf(i)); + } } - - }}} --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tapestry.apache.org For additional commands, e-mail: dev-h...@tapestry.apache.org