Smoother UI
Often an action, when invoked, will return the target (in other words, will "return this"). The 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.
Any properties with @PropertyLayout#repainting set to
NO_REPAINTare 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 thecauseway.viewer.wicket.redirectEvenIfSameObjectconfiguration 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 layout() method.
For example:
import lombok.Getter;
import lombok.Setter;
public class Customer {
@Getter @Setter
@PropertyLayout(hidden=ALWAYS)
private String layout;
public String layout() { (1)
return layout;
}
@ActionLayout(
redirect=EVEN_IF_SAME (2)
)
public Customer switchToEditMode() {
setLayout("edit");
return this;
}
}
| 1 | specifies the alternate layout to use, eg Customer-edit.layout.xml. |
| 2 | 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).