Now we'll use Java and XML annotations to customize the view, implemented with Echo2. Firstly, we are going to customize UsersPostMain class to only show posts and their comments in the main page. We hide the filter used to search and render posts as a rowset with ViewField annotation. To hide actions buttons, we edit UsersPostMain.xml file to avoid to complex the code in the original class.
<?xml version="1.0" encoding="UTF-8"?>
<class xmlns="http://www.romaframework.org/xml/roma" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="http://www.romaframework.org/xml/roma http://www.romaframework.org/schema/roma.xsd">
<fields>
<field name="entity">
<aspects>
</aspects>
<class>
<fields>
</fields>
</class>
</field>
</fields>
<actions>
<action name="search">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="create">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="read">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="update">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="delete">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="selectAll">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="deselectAll">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="Users">
<aspects>
<view visible="false" />
</aspects>
</action>
<action name="back">
<aspects>
<view visible="false" />
</aspects>
</action>
</actions>
</class>
To change the representation of each post, UsersPostListable.xml is modificated.
<?xml version="1.0" encoding="UTF-8"?>
<class xmlns="http://www.romaframework.org/xml/roma" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="http://www.romaframework.org/xml/roma http://www.romaframework.org/schema/roma.xsd">
<fields>
<field name="entity">
<aspects>
<view label=" " layout="form" />
</aspects>
<class>
<fields>
<field name="title">
<aspects>
<view label=" " render="label"></view>
</aspects>
</field>
<field name="content">
<aspects>
<view label=" " render="html"></view>
</aspects>
</field>
<field name="postedOn">
<aspects>
<view visible="false"></view>
</aspects>
</field>
<field name="comments">
<aspects>
<view label=" " render="rowset"></view>
</aspects>
</field>
</fields>
</class>
</field>
</fields>
</class>
Also, we customize the representation of the comments in CommentInstance.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<class xmlns="http://www.romaframework.org/xml/roma" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="http://www.romaframework.org/xml/roma http://www.romaframework.org/schema/roma.xsd">
<fields>
<field name="entity">
<class>
<aspects>
</aspects>
<fields>
<field name="text">
<aspects>
<view label="Comment" render="text"></view>
</aspects>
</field>
</fields>
</class>
</field>
</fields>
</class>
To customize the comments representation inside each post, we add a ViewField annotation in Comment class.
@ViewField(label = "Comment:", render = "label")
public String getText() {
return text;
}
Finally, in PostInstance.xml we add some annotations to improve the creation of a new post. With required propierty, we ensure that some attributes are not null and with render propierty, we extend the possiblities to represent the content of a post.
<?xml version="1.0" encoding="UTF-8"?>
<class xmlns="http://www.romaframework.org/xml/roma"
xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="http://www.romaframework.org/xml/roma http://www.romaframework.org/schema/roma.xsd">
<fields>
<field name="entity">
<class>
<aspects>
</aspects>
<fields>
<field name="postedOn">
<aspects>
<view required = "true"/>
</aspects>
</field>
<field name="title">
<aspects>
<view required = "true"/>
</aspects>
</field>
<field name="content">
<aspects>
<view render = "richtext"/>
</aspects>
</field>
<field name="comments">
<aspects>
<view visible = "true"/>
</aspects>
</field>
</fields>
</class>
</field>
</fields>
</class>
0 Ficheros adjuntos