GetStyle

From JRapid

Jump to: navigation, search

The getStyle method is generated for every entity in the corresponding entity abstract class. This method can be overwritten to provide customized styles in the form of CSS properties for each row of a listing.

Example

Take the entity Company, defined as follows.

    <entity label="Company" menu="Menu" name="Company">
        <property display="primary" label="Name" name="name"/>
        <property label="Status" display="secondary" name="status" type="enum">
            <enum value="N">New</enum>
            <enum value="C">Confirmed</enum>
            <enum value="A">Archived</enum>
        </property>
        <property entity="Country" label="Country" name="country"/>
    </entity>

If you want to show rows with different font color according to the status property value, you could edit the Company.java file and add the following code to your getStyle method.

public class Company extends CompanyAbstract  {

	@Override
	public String getStyle() {
		
		if("N".equals(this.getStatus())) {
			return "color: green;";
		} else if("A".equals(this.getStatus())) {
			return "color: red;";
		}
		
		return super.getStyle();
	}

}

And the listing is shown with rows in different colors.

List using the getStyle method

Be very careful when writing the getStyle method as you may try to access a property value that is null at some moment and this will block your list from rendering.

Personal tools