java - 如何根据 OpenXava 的引用值定义每一行的颜色/样式?
问题描述
我有一个引用实体优先级的实体问题。我希望在我的 OpenXava 模块的列表模式中,根据优先级的值,为每一行提供不同的颜色和视觉样式。
这是我的问题实体的代码:
package com.yourcompany.tracker.model;
import java.time.*;
import javax.persistence.*;
import org.openxava.annotations.*;
import org.openxava.calculators.*;
import org.openxava.model.*;
import lombok.*;
@Entity @Getter @Setter
public class Issue extends Identifiable {
@Column(length=100) @Required
String title;
@Stereotype("SIMPLE_HTML_TEXT")
String description;
@ReadOnly
@DefaultValueCalculator(CurrentLocalDateCalculator.class)
LocalDate createdOn;
@ManyToOne(fetch=FetchType.LAZY, optional=true)
@DescriptionsList
Priority priority;
}
这是优先级:
package com.yourcompany.tracker.model;
import javax.persistence.*;
import javax.validation.constraints.*;
import org.openxava.annotations.*;
import lombok.*;
@Entity @Getter @Setter
public class Priority {
@Id @Max(9)
int level;
@Column(length=40) @Required
String description;
}
这是我想要达到的效果:
请注意,低优先级的行是灰色的,高优先级的行是粗体的。
我知道有一个@RowStyle 注释,但似乎它是针对简单属性的。如何根据引用 (@ManyToOne) 值为每一行定义不同的样式?
解决方案
@RowStyle 允许您使用限定属性,即引用的属性。因此,您可以通过以下方式在实体的 @Tab 注释内使用 @RowStyle:
@Entity @Getter @Setter
@Tab(
rowStyles= {
@RowStyle(style="high-priority", property="priority.level", value="7"),
@RowStyle(style="low-priority", property="priority.level", value="3"),
}
)
public class Issue extends Identifiable {
请注意@RowStyle 中的属性属性我们如何使用“priority.level”,因此我们引用了优先级引用的属性。如上所述,当 priority.level 为 7 时,我们应用高优先级样式,当它为 3 时,我们应用低优先级。这些样式是在您的 custom.css 文件中定义的 CSS 类,因此:
.high-priority {
font-weight: bold;
}
.low-priority {
color: lightgray !important;
}
要了解更多信息,请阅读有关 @RowStyle 的 OpenXava 参考指南。
推荐阅读
- angular - Angular 8 Auto Reload 从 google firebase 重置密码链接重定向到登录
- python - 在 HTML 源代码中找不到该属性,但 Python 程序运行正常
- html - SVG过滤器没有改变填充颜色
- ios - 从 Xcode 11.3 启动 iOS 模拟器并出现黑屏
- c# - System.ArgumentNullException:'值不能为空参数名称:源'
- csv - 在 Model Codeigniter 中使用 where 子句导入 CSV
- php - 如何在 Magento 的产品标题中附加 sku。?
- office365 - 将元数据添加到 SharePoint 网站集
- python - AttributeError: 'WebElement' object has no attribute 'copy' error when move the function Select to a common file using Selenium Python through Django
- python - ModuleNotFoundError:没有名为“utils_io”的模块