单击按钮时将参数发送到控制器-Java Play

时间:2019-07-20 11:10:47

标签: java html api playframework

我试图在单击某个功能的按钮时发送参数。但是,出现以下错误:

  

app / views / index.scala.html:44:84:找不到:值postid [错误]
  

index.scala.html:

<section class="search-sec">
    <div class="container">
        <form action="window.location.href='@routes.AppController.retrieveByFields(postid, text_filter)';" method="get" novalidate="novalidate">
            <div class="row">
                <div class="col-lg-12">
                    <div class="row">
                        <div class="col-lg-3 col-md-3 col-sm-12 p-0">
                            <input type="text" id="postid" name = "postid" class="form-control search-slt" placeholder="Enter Post Id" required>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-12 p-0">
                            <input type="text" id= "text_filter" name="text_filter" class="form-control search-slt" placeholder="Enter text to search">
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-12 p-0">
                            <input type="submit" button type="button" class="btn btn-danger wrn-btn">Search</button>                            
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</section>

路线

GET     /comments/:id               controllers.AppController.retrieveByFields(id: Int, text: java.util.Optional[String])

控制器功能

public Result retrieveByFields(int postid, java.util.Optional<String> text) throws IOException, ParseException 

我在做什么错? 谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在您的视图文件中,它不知道您的postid是什么。两件事:

  1. 您是否已在控制器中定义了表单值?
  2. 您已将其传递给您的意见了吗?