Clone wiki

AspectFaces / 3.Usage

3. Usage

Aspect Faces framework is designed to simply generate forms or views from given entity instances. Thus the usage is simple: use AF component and pass the instance to it. The rest is done automatically, all aspects are considered and weaved based on their configuration and current user's profile.

So lets have backing bean named bean and its attribute named entity. Then you can generate form and view with following code:

Generate view via Aspect Faces*

<!-- Form generated via Aspect Faces -->
<af:ui instance="#{bean.entity}" edit="true"/>

<!-- Read-only view generated via Aspect Faces -->
<af:ui instance="#{bean.entity}" edit="false"/>


And that is all. Both usages publish the instance to the user in a way a developer wanted. Tag af:ui has some other configuration options:

Property name Description Usage
instance Processed and rendered instance. instance="#{bean.entity}"
edit Whether to render form or read-only view. Value is passed to widget template. If it doesn't respect it, is may not work. edit="true"
ignore Listed fields of given instance are not processed nor rendered. Ignored fields are not renderable at all. ignore="password,email,done"
renderField Given field is processed but not rendered at the first time. But during AJAX request it can change and be rendered later. Value is passed to widget template. If it doesn't respect it, is may not work. renderEmail="false"
layout Used layout template for this form/view. Otherwise, there would be no layout and widgets would be concatenated next to each other. Mentioned layout must be existing file name in WEB-INF/af/profile/layouts/ directory. layout="one-column-layout.xhtml"
config Used configuration profile. You may define multiple different widget sets and mappings between classes and widgets. The value must be valid configuration name defined in aspectfaces-config.xml file. config="table"
entity If you pass a collection as instance value to AF engine, it is unable to derive class to inspect and render. In such cases you have to define the class to render. entity="tutorial.model.Task"
prefix If you have multiple forms or view on a single page, you need to avoid collision in component identifiers. For such cases, you may define different prefixes for each af component. Value is passed to widget template. If it doesn't respect it, is may not work. prefix="myID"