0

我想访问 play.api.data.Field 中的对象。这是相关的类。

入口控制.java

@Entity
public class EntryControl extends Model {

    @Id
    public Long id;

    public String comment;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "entryControl")
    public List<EntryControlItem> entryControlItemList;

    public static Model.Finder<Long,EntryControl> find = new Model.Finder<Long,EntryControl>(Long.class, EntryControl.class);


}

EntryControlItem.java

@Entity
public class EntryControlItem extends Model{

    @Id
    public Long id;

    @ManyToOne
    @Constraints.Required
    public Analysis analysis;

    public Boolean passed;

    public String comment;

    @ManyToOne
    @Constraints.Required
    public EntryControl entryControl;

    public static Model.Finder<Long,EntryControlItem> find = new Model.Finder<Long,EntryControlItem>(Long.class, EntryControlItem.class);
}

分析.java

@Entity
@JsonSerialize(using = AnalysisSerializer.class)
public class Analysis extends Model {

    @Id
    @Formats.NonEmpty
    public Long id;

    @Constraints.Required
    public String name;

    ...

    public static Model.Finder<Long,Analysis> find = new Model.Finder<Long,Analysis>(Long.class, Analysis.class);

}

现在我在模板中迭代包含一些 EntryControlItem 对象的 EntryControl.entryControlItemList。

表格.scal

@(entrycontrolForm: Form[entrycontrol.EntryControl], status: String)

@repeat(entrycontrolForm("entryControlItemList"), min = 0) { entryControlItem =>
    @checkbox(entryControlItem("passed"),
        'lable -> "Verbergen",
        'class -> "checkbox",
        'showTable -> true)

    @entryControlItem("analysis").value // <-- the problem is here 
}

我想访问对象分析的“名称”字段。当我运行这个模板时,我在屏幕上看到“models.analysis.Analysis@1”

@entryControlItem("analysis").value // prints models.analysis.Analysis@1

如何访问 Analysis.name 的字段?

4

1 回答 1

0

好的..这很简单:-)。第二天,下一次尝试。我将属性添加到对象“analysis.name”中,这就是解决方案。它可以像访问对象一样处理。

@entryControlItem("analysis.name").value
于 2014-05-07T06:28:18.947 回答