MagmaBeansViewPage edited by Simone GianniMagma offers a number of annotations to define the view of a bean. Using annotations for view settings offer great speed during developement and prototyping, offering automatic list, display and input form generation, while a number of alternative and integrative technologies can be used to customize the view later. Also, annotations have well known limitations, which can then be addressed using more advanced techniques. View principlesSince a bean is composed of properties and actions, the view describes how these elements are to be displayed in an input form, in an output view or on a list. There is an order in which this elements are displayed; Magma supports both raw ordering and relative ordering, which consist in relating elements with others with "before" and "after". Elements can be placed on one or more layers, so that it's be possible to display customly reduced views in different situations. Also, since plain forms with all fields one after the other are boring, some elements can be placed on the side of another element. Defining view on a beanThe @MagView annotation is used to control how an element (property or action) is displayed. OrderingThe main display property is the order, which can be indicated verbatim using a number. public class User { private String name; private String surname; private Date birthday; @MagView(order=1) public String getName() { return name; } @MagView(order=2) public String getSurname() { return surnname; } @MagView(order=3) public Date getBirthday() { return birthday; } } Given this way, the output will be something like :
The other way is giving ordering rules using "before" or "after", for example : @MagView(order=1) public String getName() { return name; } @MagView(after="name") public String getSurname() { return surnname; } @MagView(after="surname") public Date getBirthday() { return birthday; } Will produce the same result, but is more flexible when it comes to extending a bean using ITD. Note that at least one element must still have an order TODO : should be possible to avoid this restriction. Side by sideAnother attribute of the @View annotation can be used to place elements side by side. For example : @MagView(order=1) public String getName() { return name; } @MagView(zone=Right,of="name") public String getSurname() { return surnname; } @MagView(after="name") public Date getBirthday() { return birthday; } In this case output will be :
LayersTODO Quite often a bean needs to be visualized with a reduced number of fields. Since this is a common scenario, it can be configured in annotations directly. Such common cases are :
Each element in the bean can be placed in one or more layers. Magma defines two layers, all and default. The layer all always contains all elements, while the layer default contains all element not explicitly excluded using "defaultLayer=false". Moreover, some view components define some specific layers :
@MagView(order=1, layers={"list","summary"})
public String getName() { return name; }
@MagView(zone=Right,of="name", layers={"list","summary"})
public String getSurname() { return surnname; }
@MagView(after="name")
public Date getBirthday() { return birthday; }
@MagView(after="birthday", layers="summary")
public String getEmail() { return email; }
// ... other getters and setters
@MagView(after="whatever", defaultLayer=false)
public Date getActivationDate() { return activationDate; }
In this example, only name and surname will be used when composing a list. When we want to display a summary of such a User bean, we will use : public htmlProducer doSummary(User user) { return Bean(user, "summary"); } And obtain :
If we don't specify "summary" when sending in output the bean, we will obtain elements on the default layer : all elements excluding "activationDate" which is marked with defaultLayer=false. Different settings on different layersIf you need to change the view settings between different view, for example display elements in a different order when in a list, you can use the @MagViews annotation :
@MagViews({
@MagView(order=1, layers="summary"),
@MagView(order=2, layers="list")
})
public String getName() { return name; }
@MagViews({
@MagView(zone=Right,of="name", layers="summary"),
@MagView(order=1, layers="list")
})
public String getSurname() { return surnname; }
Runtime customization of viewTODO View componentsTODO
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Labs > MagmaBeansView confluence
- [CONF] Apache Labs > MagmaBeansView confluence
- [CONF] Apache Labs > MagmaBeansView confluence
- [CONF] Apache Labs > MagmaBeansView confluence
