Clone wiki

AspectFaces / 7.Model-Annotations

Aspect weaving process in Aspect Faces is driven by model configuration and current context. The model comprises of fields, their names and data types but also of annotations which are bound to class or fields. These annotations are processed by AF core and passed to referred AnnotationDescriptors which read them and set variables in Aspect Faces and JavaServer Faces contexts. Those variables then may be used in widget templates and profile mappings to declare decision rules.

Model Example

Let's look at typical entity model example enhanced by additional UI and business logic annotations to ensure proper UI rendering.

Entity Example

package com.codingcrayons.aspectfaces.tutorial.model;

import com.codingcrayons.aspectfaces.annotations.UiOrder;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/** <p>Tasks to do with a responsible person.</p> */
public class Task {

    private Long identifier;

    private String name;

    private String responsible;

    private String email;

    private Integer priority;

    private Boolean done;

    public Long getIdentifier() { return identifier; }

    public void setIdentifier(Long identifier) { this.identifier = identifier; }

    @Length(min = 6)
    public String getName() { return name; }

    public void setName(String name) { = name; }

    @Length(min = 6)
    public String getResponsible() { return responsible; }

    public void setResponsible(String responsible) { this.responsible = responsible; }

    public Boolean getDone() { return done; }

    public void setDone(Boolean done) { this.done = done; }

    public String getEmail() { return email; }

    public void setEmail(String email) { = email; }

    public Integer getPriority() { return priority; }

    public void setPriority(Integer priority) { this.priority = priority; }


All used annotations are then scanned by related AnnotationDescriptor and the JSF context is configured according to this information. List of all registered AnnotationDescriptor classes is in /WEB-INF/aspectfaces-config.xml file and you are free to remove existing or add your own. A custom descriptor may look as follows:

Custom AnnotationDescriptor

public class LengthAnnotationDescriptor implements AnnotationDescriptor, VariableJoinPoint {

    public String getAnnotationName() {
        return "org.hibernate.validator.constraints.Length";

    public List<Variable> getVariables(AnnotationProvider annotationProvider) {
        List<Variable> variables = new ArrayList<Variable>();
        variables.add(new Variable("minLength", annotationProvider.getValue("min")));
        variables.add(new Variable("maxLength", annotationProvider.getValue("max")));
        return variables;

As you can see, the annotation is passed to the descriptor and it produces a list of variables to be set into JSF context. Here they are variables minLength and maxLength. Besides that you can define and use your own annotations, the only thing you need to do is to write your own AnnotationDescriptor.

Aspect Faces Default AnnotationDescriptors

By default. Aspect Faces supports a bunch of annotations mostly from Java Persistence API (JPA), Javax Validation API and Hibernate Validator. Besides that, it defines a lot of its own annotations and here follows the list of them.


Annotation Published Variables Notes
AF core entityBean Name of inspected class
AF core className Simple name of inspected class
AF core ClassName Simple name of inspected class (first upper)
AF core fullClassName Name of inspected class
AF core FullClassName Name of inspected class (first upper)
AF core fieldName Property name
AF core FieldName Property name (first upper)
AF core dataType Property type
AF core DataType Property type (first upper)
AF core instance instanceVariablePrefix (i) and entity name
AF core value Instance.field
AF core fragment Fragment name (applies to header and footer)
AF core label Human readable property name (the first field name letter as upperCase, next upperCases separated with space)


Annotation Published Variables Notes
@​Email email Boolean indicating that the value is supposed to be an email.
@​Length minLength, maxLength
@​Max max
@​Min min
@​NotNull required, notNull
@​Future future Boolean indicating that the date is meant to be in future.
@​Past past Boolean indicating that the date is meant to be in past.
@​Pattern javaPattern, javaPatternFlags
@​Range min, max


Annotation Published Variables Notes
@​ConstraintComposition compositionType
@​CreditCardNumber creditCardNumber
@​Email email
@​Length minLength, maxLength
@​NotBlank required, notBlank
@​NotEmpty required, notEmpty
@​Range min, max
@​SafeHtml safeHtml,whitelistType, additionalTags
@​ScriptAssert scriptAssert, lang, script, alias
@​URL url, protocol, host, port, regexp, flags


Annotation Published Variables Notes
@​DecimalMax max
@​DecimalMin min
@​Digits digitsize, digitfraction
@​Future future
@​Max max
@​Min min
@​NotNull required, notNull
@​Past past
@​Pattern pattern
@​Size min, max


Annotation Published Variables Notes
@​Column notNull, required, maxLength, unique, precision, scale {}
@​JoinColumn notNull, required, unique
@​Temporal temporal, temporalType

Annotation Published Variables Notes
@​Restrict value


Annotation Published Variables Notes
@​UiAfter after
@​UiBefore before
@​UiCollection collection
@​UiHtml html
@​UiLabel label
@​UiLink link
@​UiParam name,value,type
@​UiParams UiParam[]
@​UiPassword password
@​UiPattern pattern
@​UiRequired required
@​UiRestrict value
@​UiSize size
@​UiText text,cols,rows
@​UiType type