play2 calling controllers, models, views in submodule

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 02:34:43

问题


Trying to split my project to few submodules. I've created submodules: /modules/common /modules/shopping

Now I am trying convert name spaces to new one including new structure.

my controller:

package controllers.common;
public class Index extends Controller {}

my model:

package models.common;
@Entity
public class AppMode {}

my view:

@(AppModeForm: Form[models.common.AppMode], CurrentMode: Boolean)
 @helper.form(common.routes.CMS.appModeSubmit, 'id -> "form") {}

And I am getting errors all the time. F.e: an error in view:

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


[error] /home/kd/Application/modules/common/app/views/CMS/AppModeView.scala.html:9: reference to common is ambiguous;
[error] it is imported twice in the same scope by
[error] import controllers._
[error] and import models._
[error]                     @helper.form(common.routes.CMS.appModeSubmit, 'id -> "form") {
[error]                                  ^
[error] one error found

回答1:


models and controllers are automagically imported into the play templates, so this causes the problem, you would either have to not name them the same, (for example turn the package structure around to common.{models, controllers} and then explicitly import what you want from there. Of course since there might be more than one thing called routes you would still have some problems with overloading (but you can workaround by renaming things you import for the current scope like this:

@import controllers.common.{routes => commonRoutes}

@helper.form(commonRoutes.CMS.appModeSubmit, 'id -> "form") 

An easier option would be to just explicitly specify the package, like this:

@helper.form(controllers.common.routes.CMS.appModeSubmit, 'id -> "form") 


来源:https://stackoverflow.com/questions/25842651/play2-calling-controllers-models-views-in-submodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!