Wiki

Clone wiki

AspectFaces / 4.Type-Mapping

Widgets are the independent aspect which needs to be weaved with fields of the processed entity. The weaving policy is defined as a set of rules, where you can declare data types related to given default widget. Besides that, you may declare other conditions for exceptions. Better then long explanation will be an example. This example assumes profile html (set of widgets) located in /WEB-INF/af/profile/html directory.

Mapping file

#!xml


<?xml version="1.0" encoding="UTF-8"?>
<configuration
        xmlns="http://aspectfaces.com/schema/aspectfaces"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        
        xsi:schemaLocation="
            http://aspectfaces.com/schema/aspectfaces 
            http://www.aspectfaces.com/schema/af-configuration-1.4.0-SNAPSHOT.xsd
        ">

    <mapping>
        <type>String</type>
        <default tag="html/text.xhtml" maxLength="255" size="30" required="false"/>
        <condition
            expression="${not empty email and email == true}"
            tag="html/email.xhtml"
        />
        <condition
            expression="${not empty password and password == true}"
            tag="html/password.xhtml"
        />
    </mapping>

    <mapping>
        <type>Integer</type>
        <type>int</type>
        <default tag="html/number.xhtml" maxLength="50" size="10" required="false"/>
    </mapping>

    <mapping>
        <type>Task</type>
        <default tag="html/entity.xhtml" required="false"/>
    </mapping>

    <mapping>
        <type>Boolean</type>
        <type>boolean</type>
        <default tag="html/boolean.xhtml" required="false"/>
    </mapping>

    <!-- Globally ignored fields -->
    <ignore-fields>
        <name>id</name>
        <name>version</name>
        <name>createdBy</name>
        <name>realInstitution</name>
        <name>categoryId</name>
        <name>statusDate</name>
        <name>created</name>
        <name>modified</name>
    </ignore-fields>

</configuration>

Mappings are considered as Aspect Faces profiles and you can choose between them by config attribute of af:ui tag. Mappings are usually named as profile-name.config.xml files and places into /WEB-INF/af.

Used variables are located in Aspect Faces context and set by Annotation Inspectors. For example, if the field is annotated with @Email and there is a proper inspector reading this annotation, it can set the email variable to true. About Annotation inspectors (named also Annotation Descriptors) keep reading.

Updated