:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

The `typicalLength` element is intended to indicate the size that a textfield should be rendered as a visual indicator of the expected length:

* for properties, the element can be specified using either the `@PropertyLayout` annotation, or a meta-annotation, or using the `Xxx.layout.xml` layout file.

* for parameters, the element can be specified using either the `@ParameterLayout` annotation, or a meta-annotation.

[CAUTION]
====
The Wicket viewer does not use this element, instead preferring to render all textfields as the same size irrespective.

In other words, providing this element has no impact on the UI (as rendered by the Wicket viewer, at least).
====

[NOTE]
====
`@Property#maxLength()` and `@PropertyLayout#typicalLength()` are not related - the first prevents the property from holding more than the specified number of characters, the latter is a layout hint relating to the size of the textfield.
====

== Annotated

The `typicalLength` element can be specified explicitly using an annotation:

* for properties, using `@PropertyLayout#typicalLength()`:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm.java[tags=annotation]
----
<.> explicitly specifies that the property should use a textbox

* for parameters, using `@ParameterLayout#typicalLength()`:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm_updateWithParameterLayout.java[tags=annotation]
----
<.> explicitly specifies that the parameter should use a textbox

== Layout File

For properties (not parameters), the `typicalLength` element can be specified using the `Xxx.layout.xml` file:

* property definition:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm.java[tags=layout-file]
----
<.> `typicalLength` hint is _not_ present.

* layout file snippet:
+
[source,xml,indent=0,tabsize=4]
----
<cpt:property id="propertyUsingLayout" typicalLength="10"/>
----
// TODO: for some reason this doesn't include correctly in the app...
//include::PropertyLayoutTypicalLengthVm.layout.xml[tags=layout-file]

One advantage of the layout file over the annotation is that the layout file is dynamic: it can be modified and the changes reloaded in a running application.

TIP: It is sometimes necessary to invoke the `Rebuild Metamodel` action to see this take effect.

== Contributed

The `@PropertyLayout` can also be applied at the class-level to mixin properties:.

[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm_mixinProperty.java[tags=class]
----
<.> explicitly specifies that the contributed property should use a textbox

== Meta-annotated

The `typicalLength` element can also be specified using a custom meta-annotation:

* the meta-annotation is defined as:
+
[source,java]
----
include::TypicalLengthMetaAnnotation.java[tags=class]
----
<.> annotated for a property ...
<.> \... and for a parameter.
<.> annotation can be applied to a property (either its getter or the field directly)
<.> annotation can be applied to a parameter
<.> annotation can be applied to a type (ie, meta-meta annotations recursively)

* and can be applied to a property:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm.java[tags=meta-annotated]
----
<.> hint is inherited from the meta-annotation

* or can be applied to a parameter:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm_updateWithMetaAnnotation.java[tags=meta-annotation]
----
<.> hint is inherited from the meta-annotation

* or can be applied to mixin:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm_mixinPropertyWithMetaAnnotation.java[tags=class]
----
<.> hint is inherited from the meta-annotation

=== Meta-annotated Overridden

The meta-annotation can itself be overridden:

* in a property:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm.java[tags=meta-annotated-overridden]
----
<.> hint from meta-annotation ...
<.> \... is overridden by the `@PropertyLayout` annotation

* or a parameter:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm_updateWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden]
----
<.> hint from meta-annotation ...
<.> \... is overridden by the `@ParameterLayout` annotation


* or a mixin:
+
[source,java,indent=0]
----
include::PropertyLayoutTypicalLengthVm_mixinPropertyWithMetaAnnotationOverridden.java[tags=meta-annotation-overridden]
----
<.> hint from meta-annotation ...
<.> \... is overridden by the `@PropertyLayout` annotation

