【问题标题】:Play Framework Template Field value as Object将框架模板字段值作为对象播放
【发布时间】:2014-05-07 14:28:18
【问题描述】:

我想访问 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 
}

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

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

如何访问 Analysis.name 的字段?

【问题讨论】:

    标签: playframework playframework-2.0 scala-template


    【解决方案1】:

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

    @entryControlItem("analysis.name").value
    

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 2013-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 2012-07-23
      • 1970-01-01
      相关资源
      最近更新 更多