=== Maximum (string) length

: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.
:page-partial:



The xref:applib:index/annotation/Property.adoc#maxLength[maxLength()] attribute applies only to `String` properties, indicating the maximum number of characters that the user may enter (for example in a text field in the UI).
The attribute It is ignored if applied to properties of any other type.

That said, properties are most commonly defined on persistent domain objects (entities), in which case the JDO xref:refguide:applib-ant:Column.adoc[@Column] will in any case need to be specified.
Apache Isis can infer the `maxLength` semantic directly from the equivalent `@Column#length()` annotation/attribute.

For example:

[source,java]
----
import lombok.Getter;
import lombok.Setter;

public class Customer {

    @javax.jdo.annotations.Column(length=30)
    @Getter @Setter
    private String firstName;

    // ...
}
----

In this case there is therefore no need for the `@Property#maxLength` attribute.

== Non-persistent properties

Of course, not every property is persistent (it could instead be derived), and neither is every domain object an entity (it could be a view model).
For these non persistable properties the `maxLength` attribute is still required.

For example:

[source,java]
----
public class Customer {

    @javax.jdo.annotation.NotPersistent                         // <.>
    @Property(maxLength=100)
    public String getFullName() { /* ... */ }                   // <2>
    public void setFullName(String fullName) { /* ... */ }      // <3>
    ...
}
----
<.> a non persisted (derived) property
<.> implementation would most likely derive full name from constituent parts (eg first name, middle initial, last name)
<.> implementation would most likely parse the input and update the constituent parts

== See also

This attribute can also be applied to xref:refguide:applib:index/annotation/Parameter.adoc#maxLength[parameters].

