Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A Component Mixin is a way to supplement an existing Tapestry component with additional behavior.

{
Div
Wiki Markup
style
float:right
titleRelated Articles
classaui-label
Content by Label
showLabelsfalse
showSpacefalse
titleRelated Articles
cqllabel in ("component-classes","mixins") and space = currentSpace()
|background=#eee} {contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=component-classes,mixins} {float}

You can think of a mixin as a kind of mashup for a component; it combines the new behavior of the mixin with the existing behavior of the component, and bundles it all in one place. Mixins may be used to add specialized validation to user input fields, dynamically modify the HTML output of a component, or to add Ajax effects and behaviors of all sorts to components.

...

Mixins are allowed to have parameters, just like components.

When binding parameters (either in the template, or using the parameters attribute of the Component annotation), Tapestry will match each parameter name against the parameters defined by each class (which is to say, the component and each mixin).

If the component and a mixin both define a parameter with the same name, then the component wins: the component's parameter will be bound, and the mixin's parameter will be unbound.

Here we provide a value of ".5" seconds for the Autocomplete mixin's "frequency" parameter:

Code Block
languagexml
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
...
<t:textfield t:id="accountName" t:mixins="Autocomplete" t:Autocomplete.frequency=".5" />

The parameter name should be prefixed with the name of the mixin class ("Autocomplete." above).

You can do the same thing with the @Component annotationAlternately, you may prefix the name of the parameter with the unqualified name of the Mixin class; this eliminates the ambiguity. Example:

Code Block
languagejava
  @Component(parameters={"Autocomplete.idfrequency=auto.5", . . . }) 
@Mixins("Autocomplete", "DefaultFromCookie"})
  private TextField userId;

When using the Tapestry 5.3 and earlier XSDs, you may omit the class name prefix (e.g. t:frequency=".5" instead of t:Autocomplete.frequency=".5"), but then Tapestry has to resolve conflicts. If a component and a mixin both define a parameter with the same name, the component wins; the component's parameter will be bound, and the mixin's parameter will be unbound.

If the component and a mixin both supports informal parameters, the mixin will receive the all the unqualified informal parameters. If more than one Mixin supports informal parameters the results are undefined.

...

Code Block
languagejava
  @BindParameter("translate")
  private FieldTranslator translator;

In same some cases, a mixin will be used on different components using different names for a similar parameter type. For instance, BeanEditor has an "object" parameter; most form fields have a "value" parameter, and Grid has a "source" parameter. These parameters have different names, but share the feature of being the each is the "principle" parameter on which the components are acting. A mixin useable by all three components can specify multiple potential parameter values to bind. The first value that matches a declared parameter of the associated component will be used:

...

In addition, the following mixins are available from other sources:

ClickOnce

From JumpStart, a mixin to apply to a submit button, ensuring it can't be double-clicked

Confirm

Adds a JavaScript confirm prompt to any link

ZoneUpdaterUpdates a zone when a client-side event occurs

Additional Tools

Tapestry-Xpath is a third-part Tapestry module that allows XPath traversal of the Tapestry (server-side) DOM, which can be extremely useful in certain mixins.

Scrollbar