[[title]]
= `title()`

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



Every object is represented by a title.
This appears both as a main header for the object when viewed as well as being used as a hyperlink within properties and collections.
It therefore must contain enough information for the end-user to distinguish the object from any others.

This is most commonly done by including some unique key within the title, for example a customer's SSN, or an order number, and so forth.
However note that Apache Isis itself does _not_ require the title to be unique; it is merely recommended in most cases.

An object's title can be constructed in various ways, but the most flexible is to use the `title()` method.
The signature of this method is usually:

[source,java]
----
public String title() {
    // ...
}
----

Note that Apache Isis' xref:userguide:btb:i18n.adoc[i18n support] extends this so that titles can also be internationalized.

For example, in a todoapp we can use this technique to change the title of items that have been completed:

[source,java]
----
public String title() {
    if (isComplete()) {                                         // <.>
        return getDescription() + "- Completed!");
    } else {
        final LocalDate dueBy = getDueBy();
        if (dueBy != null) {                                    // <.>
            return getDescription() + " due by " + dueBy);
        } else {
            return getDescription();
        }
    }
}
----
<.> imperative conditional logic
<.> imperative conditional logic

As the example above shows, the implementation can be as complex as you like.

In many cases, though, you may be able to use the xref:refguide:applib:index/annotation/Title.adoc[@Title] annotation.

