简体   繁体   English

如何在Play Framework 2.3中从我的表单反向路由到操作

[英]How to reverse route to an action from my form in Play Framework 2.3

Good day Everyone, 今天是个好日子,

I am new to Play framework and am trying to get started building an application. 我是Play框架的新手,正在尝试开始构建应用程序。 Under the app/controllers folders i have created sub packages so i have something like app/controllers/products/ProductController.class . app/controllers文件夹下,我创建了子包,因此我有一些类似于app/controllers/products/ProductController.class

In my routes.conf file i have added a sample route like this 在我的routes.conf文件中,我添加了这样的示例路由

GET /createproduct controllers.products.ProductController.listAllProducts() POST /createproduct controllers.products.ProductController.createProductDetail()

and i can goto the url http://localhost:9000/createproduct and see a sample view that i created. 我可以转到URL http://localhost:9000/createproduct并查看我创建的示例视图。

My issue now is that i want to add a form to the view and when i try to use the form helper method to POST data to the POST URL above from my new view like this 我现在的问题是我想向视图中添加表单,并且当我尝试使用表单助手方法将数据从我的新视图中发布到上述POST URL时,如下所示

@helper.form(action = routes.products.ProductController.createProductDetail()) {

i get the error that 我得到的错误

value products is not a member of object controllers.routes

All the samples that i saw online only use the route.Application example which is doesnt fit my issue. 我在网上看到的所有示例仅使用route.Application示例,这不适合我的问题。

So my question is how do i reverse route to this action or route from a view using the Form helper 所以我的问题是我该如何反向路由到该操作或使用表单帮助程序从视图反向路由

The valid syntax is: 有效语法为:

[full-package-name].routes.[controller].[method]

So in your case it should be 所以你的情况应该是

 controllers.products.routes.ProductController.createProductDetail()

controllers.routes is imported implicity, therefore for using with controllers in default package you can short it to: controllers.routes是隐式导入的,因此要与默认包中的控制器一起使用,可以将其缩写为:

routes.Controller.action()

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

相关问题 播放框架:如何以表格形式制作动态路线 - Play framework : How to make dynamic route in form 删除表单中断播放框架(2.3)中的输入 - Remove input in form breaks play framework (2.3) 如何从SBT Play Framework 2.3项目的源中排除目录 - How to exclude directory from source in an SBT Play Framework 2.3 project 如何在play framework 2.3中编写cron job - how to write cron job in play framework 2.3 如何从Play 2 Java上的路由反向生成绝对URL? - How to reverse generate an absolute URL from a route on Play 2 Java? Play Framework 2.5 - 从scala.html文件反向到.java文件中的变量的路由 - Play Framework 2.5 - Reverse route to a variable in .java file from scala.html file 如何从Play框架中的表单读取日期 - How to read date from form in play framework 播放框架反向路由期望在IntelliJ IDEA中什么都不作为参数 - Play framework reverse route expects Nothing as parameter in IntelliJ IDEA 如何在play(2.3)框架内的Java控制器代码中从String变量构造Html对象 - How do I construct an Html object from a String variable in Java controller code within the play (2.3) framework 如何在Play 2.3中自定义操作组合以记录请求和响应? - How to do custom action composition to log request and response in Play 2.3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM