Date: Tue, 19 Mar 2024 01:34:15 +0000 (UTC) Message-ID: <1499693229.52638.1710812055410@cwiki-he-fi.apache.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_52637_2058764544.1710812055409" ------=_Part_52637_2058764544.1710812055409 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Many of the components provided with Tapestry share a common behavior: i= f the component's id matches a property of the container, then some paramet= er of the component (usually value) defaults to that property.
This is desirable, in terms of not having to specify the component's id = and then specify the same value as some other parameter.
Let's say you have created a component, RichTextEditor
, whi=
ch operates like a normal TextArea component, but provides a JavaScript ric=
h text editor. You might start with something like:
public class = RichTextEditor implements Field { @Property @Parameter(required=3Dtrue) private String value; . . . // Lots more code not shown here }
However, the weakness here is when you make use of the component. You te= mplate may look like:
<t:labe= l for=3D"profile"/> <br/> <t:richtexteditor t:id=3D"profile" value=3D"profile"/>
Every component has a unique id; if you don't assign one with the =
t:id
attribute, Tapestry will assign a less meaningful one. Componen=
t ids can end up inside URLs or used as query parameter names, so using mea=
ningful ids helps if you are ever stuck debugging a request.
This repetition can be avoided by adding the autoconnect attrib= ute to the @Parameter annotation:
@Property @Parameter(required=3Dtrue, autoconnect=3Dtrue) private String value;
This can now be written as <t:richtexteditor t:id=3D"profile"/&=
gt;
. The unwanted repetition is gone: we set the id of the component=
and the property it edits in a single pass.
If there is no matching property, then a runtime exception will be throw= n when loading the page because the value parameter is required and not bou= nd.
The most common case of using autoconnect is form control components suc= h as TextField and friends ... or this RichTextEditor.