将框架模板字段值作为对象播放

时间:2014-05-06 16:26:55

标签: playframework playframework-2.0 scala-template

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

EntryControl.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);
}

Analysis.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);

}

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

form.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 
}

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

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

如何访问Analysis.name?

字段

1 个答案:

答案 0 :(得分:0)

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

@entryControlItem("analysis.name").value