繁体   English   中英

当从视图中引用控制器中的Java类时,Play Framework编译错误“类型索引不是对象控制器的成员。应用程序”

[英]Play Framework compile error “type Index is not a member of object controllers.Application” when referring to Java class in controller from view

我正在尝试就此寻求其他开发人员的帮助,但似乎无法解决此问题。 我正在编译Play应用程序,并且不断收到此错误:

C:\myapp\app\views\index.scala.html:1: type Index is not a member of object controllers.Application
[error] @(indexForm: Form[Application.Index])

我已经审查了我编写的其他应用程序,但是找不到解决方案。

这是控制器:

public class Application extends Controller {

    public class Index {
        public String name;
        public String title;
    }

public Result index() {
    // Open the index page...
    return ok(index.render(form(Index.class)));
}

...
}

这是视图:

@(indexForm: Form[Application.Index])

@main(null) {
    <section id="homePage">
        <div class="container">
            <h3><b>Here is your index page</b></h3>
            <div class="testimonials">
                <div class="item">
                    <div class="testim_content">You can customize this as your landing page</div>
                </div>
            </div>
            <div class="container">
                <div class="row" style="margin: auto;">
                    <div class="col-sm-3">
                        <a href="/add$$APPNAME$$" class="buttonCustomView" style="color: #FFFFFF;">Add New " + mainTable + "</a>
                    </div>
                    <div class="col-sm-3">
                        <a href="/view$$APPNAME$$" class="buttonCustomView" style="color: #FFFFFF;">View All " + mainTable + "</a>
                    </div>
                    <div class="col-sm-3">
                        <a href="/login" class="buttonCustomView" style="color: #FFFFFF;">Login</a>
                    </div>
                </div>
            </div>
        </div>
    </section>
}

我一直在评论这个帖子:

Play框架-值登录不是控制器的成员。

Play Framework for Scala:编译错误[类型应用程序不是软件包控制器的成员]

我曾尝试重命名课程,但仍然没有运气。

我知道这可能是一个简单的答案,但是我无法弄清楚它是什么。

感谢您的帮助。

尝试这个 :

在控制器中

... 

@Inject
FormFactory formFactory;

public Result index() {

    Index index = new Index();
    index.set..
    ...

    Form<Index> indexForm = formFactory.render(form(Index.class)));

    return ok(views.html.index.render(indexForm.fill(index)));

}

视野中

@(indexForm: play.data.Form[controllers.Application.Index])

如果没有成功,请将Index类移到新程序包中,然后尝试使用[package_name.Index]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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