[[validity]]
= Validity

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


== Properties

Property edits can also be validated:

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

@Property(editing = Editing.ENABLED)            // <.>
@Getter @Setter
private String status;

public String validateStatus(String status) {   // <.>
    // ...
}
----
<.> if required
<.> "validate" prefix, suffix matches up with the property name, takes and returns a string.
A non-null value is the reason why the

== Action parameters

Action arguments can be validated either singly or as a set.
For example:

[source,java]
----
public Customer placeOrder(Product p, int quantity) {
    // ...
}
public String validate0PlaceOrder(Product p) {                  // <.>
    // ...
}
public String validate1PlaceOrder(int quantity)  {              // <.>
    // ...
}
public String validatePlaceOrder(Product p, int quantity)  {    // <.>
    // ...
}
----
<.> "validate" prefix, N-th param; suffix matches action, param of correct type. +
Validates the 0th argument of the action, ie `Product`. +
A non-`null` return string is taken as the _reason_ why the action argument is invalid.
<.> similarly, N-th param. +
Validates the 1st argument of the action, ie `int quantity`
<.> validates all the arguments of the action together. +
A non-`null` return string is taken as the _reason_ why the action arguments taken together are invalid.

The framework validates each argument separately; only if all are valid does it check all the arguments together.

[TIP]
====
If the action is implemented as a xref:mixins.adoc[mixin], then the `disableXxx` supporting method can be matched to the action parameter xref:mixins.adoc#using-the-parameter-name[by name] and also using xref:mixins.adoc#using-a-parameters-class[Parameters] class.
====


== For more information

For more information, see the xref:refguide:applib-methods:prefixes.adoc#validate[validate...()] section in the appropriate reference guide.
The reference guide also explains how to define validation declaratively, using the xref:refguide:applib:index/annotation/Parameter.adoc#mustSatisfy[@Parameter#mustSatisfy()] or xref:refguide:applib:index/annotation/Property.adoc#mustSatisfy[@Property#mustSatisfy()] attributes.

It's also possible to return xref:userguide:btb:i18n.adoc[locale-specific] strings, by returning xref:refguide:applib:index/services/i18n/TranslatableString.adoc[TranslatableString] instead of `java.lang.String`.


