[英]How to apply a @RowStyle to a range of rows (or other complex condition) in OpenXava?
I understand that using @RowStyle I can determine the style depending on specific values of a field.我知道使用 @RowStyle 我可以根据字段的特定值确定样式。 But how can I do it if I want to differentiate the five first records (id >= 1 and id <= 5) from the other ones?
但是,如果我想将前五个记录(id >= 1 和 id <= 5)与其他记录区分开来,我该怎么做呢?
For example, in my case an Activity entity starts with 5 activites by default.例如,在我的例子中,一个活动实体默认以 5 个活动开始。 The goal is to show those first 5 rows with a different color or style and the rest of the records, added by the user, with regular style.
目标是以不同的颜色或样式显示前 5 行,以及用户添加的记录的 rest 以常规样式显示。 Like this:
像这样:
How can I apply the style just to the first 5 rows?如何将样式仅应用于前 5 行?
@RowStyle does not allow you to define complex logic, but just compares the value of a property. @RowStyle 不允许您定义复杂的逻辑,而只是比较属性的值。 However, you can achieve it defining a calculated property where you can put that logic.
但是,您可以定义一个计算属性来实现它,您可以在其中放置该逻辑。 Something like this:
像这样的东西:
import javax.persistence.*;
import org.openxava.annotations.*;
import lombok.*;
@Entity @Getter @Setter
@Tab(
rowStyles={
@RowStyle(style="row-highlight", property="type", value="default"),
@RowStyle(style="row-red", property="type", value="extra")
}
)
public class Activity {
@Id
int id;
@Column(length=50) @Required
String description;
public enum Type { DEFAULT, NORMAL, EXTRA };
public Type getType() {
if (id >= 1 && id <= 5) return Type.DEFAULT;
if (id > 100) return Type.EXTRA;
return Type.NORMAL;
}
}
Note the type property where we put the logic that determines the style.请注意我们放置确定样式的逻辑的type属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.