Routes and subpackages in controllers

梦想与她 提交于 2019-12-05 12:38:07

问题


I'm using Play 2.1 and I'm having some odd problems.

I have a subpackage messages in the controllers package with a class i18n.java.

My routes file looks like this:

GET     \    controllers.messages.i18n.index()
POST    \    controllers.messages.i18n.process()

I now have a form with the following action:

@helper.form(action = routes.messages.i18n.process())

but this gives me an error:

value messages is not a member of object controllers.routes

I've used subpackages before in Play 2.0.4 and it worked fine like that, can anyone spot any errors in my configuration?

The routes file doesn't complain that it can't find the controller.


回答1:


The route should be controllers.messages.routes.i18n.process(). You can inspect the target/scala-2.10/src_managed directory to discover generated files.

And for information, Java coding conventions say that a class must start with an uppercase.




回答2:


FYI, in 2.2 it's slightly different.

routes.conf looks like:

GET  /admin/stuff  controllers.admin.StuffController.show()

in code looks like:

controllers.admin.routes.StuffController.show()



回答3:


For Play 2.4.6 Java users:

Let's say your controller (Application) and action (logout) is com.stackoverflow.play.Application.logout().

To use it in your template (*.scala.html), you do @com.stackoverflow.play.routes.Application.logout (e.g., <a href="@com.stackoverflow.play.routes.Application.logout()">, <form action="@com.stackoverflow.play.routes.Application.logout()" method="post">).

Read the bottom part of this link: https://playframework.com/documentation/2.4.x/JavaRouting



来源:https://stackoverflow.com/questions/17010595/routes-and-subpackages-in-controllers

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