=== Smoother UI

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

Often an action, when invoked, will return the target (in other words, will "return this").
The xref:refguide:applib:index/annotation/ActionLayout.adoc#redirectPolicy[redirectPolicy()] element is used to control how the object is re-rendered.

There are three options:

* if set to `ONLY_IF_DIFFERS`, then the existing web page will not be re-rendered, rather it will be updated in-place (using Ajax).
+
This makes for a smoother UI.
+
[NOTE]
====
Any properties with xref:refguide:applib:index/annotation/PropertyLayout.adoc#repainting[@PropertyLayout#repainting] set to `NO_REPAINT` are then _not_ updated.
====

* if set to `EVEN_IF_SAME`, then a redirect occurs and a new web page is rendered.

* if set to `AS_CONFIGURED`, then the default behaviour is as specified by the `causeway.viewer.wicket.redirectEvenIfSameObject` xref:vw:ROOT:setup-and-configuration.adoc[configuration property]).

One use case for choosing `EVEN_IF_SAME` is if the action "returning this" is intended in some way to require that the object use a different layout, as per multiple layout support, as specified using the xref:refguide:applib-methods:ui-hints.adoc#layout[layout()] method.

For example:

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

public class Customer {

    @Getter @Setter
    @PropertyLayout(hidden=ALWAYS)
    private String layout;

    public String layout() {                // <.>
        return layout;
    }

    @ActionLayout(
        redirect=EVEN_IF_SAME               // <.>
    )
    public Customer switchToEditMode() {
        setLayout("edit");
        return this;
    }
}
----

<.> specifies the alternate layout to use, eg `Customer-edit.layout.xml`.

<.> even though this action returns the same target object, still re-render the page.

If `switchToEditMode()` action is invoked, then the UI will attempt to render the customer using a `Customer.layout.edit.xml` layout file (instead of the default `Customer.layout.xml`).

