简体   繁体   中英

Getting “reference is ambiguous and double imported” errors in a simple form

I have following very simple model and a view

package models;

import play.db.ebean.Model;

import javax.persistence.Entity;

@Entity
public class Safari extends Model {

    public String name;
}

views/safari/add.html.scala

@(myForm: play.data.Form[Safari])

@helper.form(action = routes.Safari.submit()) {
  @helper.inputText(myForm("username"))
  @helper.inputPassword(myForm("password"))
}

I am getting following error after adding the line @(myForm: play.data.Form[Safari]) in the view

reference to Safari is ambiguous; it is imported twice in the same scope by import controllers._ and import models._

The controllers and models packages are imported by default in your views. Since you have both a controller and a model named Safari the compiler doesn't know which one to use for play.data.Form[Safari] .

You need to either rename your controller or model to differentiate them or use the full package name in your view.

@(myForm: play.data.Form[models.Safari])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM