Tapestry5 jQuery provides jQuery Components and can fully replace Prototype and Scriptaculous by jQuery

Selector Binding

Selector Binding


Automatically injected into components that support getClientId(). This combines with the selector binding to create jQuery selectors. The selector binding supports 'this' which returns the selector for the enclosing component that supports getClientId(). For the most part the selector binding will return the correct value. Specifically you can't always get the correct selector for a named component in a loop. More specifically if a component with the same name is rendered more than once on a page the selector changes as that component is rendered. In this case the selector binding will return a selector for the currently rendering component. This may or may not be the one you want.

This demonstration page will show you How to use the selector Binding. This selector will use the Selector mixin, injected automatically to the ClientElement component. This mixin will create an array like : selector['the Tapestry Id']='#The jQuery Id';

  • - Using "this" will return the clientId of the current Element.
  • - If you want to get the clientId of specific component, you will use the t:id parameter of the component
  • - We have also an example of using the selector binding in JavaScript Callback function.
Please have a look to the template file in order to understand the demo.

Using "this" inside a component will return the clientId of the component container :
>> $('#any')

If you do not specify the t:id to your components, the selector will nethertheless use the unique t:id generated by Tapestry :
>> $('#any_0')
>> $('#any_1')

If you want to get the clientId of a specific component, you can use its t:id parameter :
>> $('#test') $('#first')

Event if we used many times "this" before, in this case, we will get the clientId of the Component container :
>> $('#any')