点击< g:actionSubmit>时,参数值在控制器中始终为空。按键 [英] params values are always null in controller on clicking <g:actionSubmit> button

查看:94
本文介绍了点击< g:actionSubmit>时,参数值在控制器中始终为空。按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有搜索按钮并根据搜索条件,我必须搜索数据。我使用了一些隐藏的变量来存储数据。

In my application, I have search button and based on the search criteria, I have to search data. I have used few hidden variables to store data.

我的.gsp页面如下所示:

My .gsp page looks like this:

<g:form id="job" name="job" method="POST">
<div>
<input type="hidden" id="country" name="country" value="${country}"/>
<input type="hidden" id="paginationFlag" name="paginationFlag" value="${paginationFlag}"/>
<!-- There are other components like text field, select box etc --> 
<g:actionSubmit id="Search" value="Search" formmethod="post"    action="findJob"/>
</div>
</g:form>

我的控制器方法如下所示:

My respective controller method looks like this:

def  findJob(){
def country
def paginationFlag

if(params?.country){
  country = params?.country
}else{
  country = 'USA'
}

if(params?.paginationFlag){
 paginationFlag = params?.paginationFlag
}else{
 paginationFlag = 'false'
}

withFormat{
 html{
  List<Applicant> searchList //get data from database.
  // other business logic
    render(view : "jobList",model:[paginationFlag: paginationFlag, country:country])
}

json{
    // some business logic
    def candidateList // value for this candidateList is acquired from database
    def json = ['jsn': candidateList]
    render json as JSON
  }
}

当我点击搜索按钮并调试代码时,首先我的控制权转到控制器 - > findJob()方法并执行html部分内的代码。
其次,它进入gsp页面(查看页面)并设置value.Third,它再次进入控制器并执行json部分内的代码。

When I click search button and debug the code, first my control goes to controller-> findJob() method and executes the code inside html part. Secondly, it goes to the gsp page (view page) and sets value.Third, it again goes to the controller and executes the code inside json part.

在控制器的第一个条目中,paginationFlag和param中的国家/地区的值均为null。因此它将分别设置值'false'和'USA'。但是当控制第二次再次进入控制器时,param.paginationFlag和params.country的值为空。他们不应该有分配的值吗?

On the first entry to the controller, the value of paginationFlag and country in param are both null. So it will set the value 'false' and 'USA' respectively. But when control goes to controller again for the second time, again the value of param.paginationFlag and params.country are null. Should not they have the assigned values?

为什么会这样?我应该怎么做第二次在params中获得国家和分页标志的价值?任何人都可以解释我吗?

Why is it so? What should I do go get the value of country and paginationFlag in params on the second time? Can any one explain me ? Thank you very much for advance.

推荐答案

问题在于你正在使用普通的HTML input 标记而不是Grails g:hiddenField 标记。试试这个:

The problem is you're using a regular HTML input tag rather than a Grails g:hiddenField tag. Try this:

<g:form id="job" name="job" method="POST">
    <div>
    <g:hiddenField name="country" value="${country}"/>
    <g:hiddenField name="paginationFlag" value="${paginationFlag}"/>
    <!-- There are other components like text field, select box etc --> 
    <g:actionSubmit id="Search" value="Search" formmethod="post"    action="findJob"/>
    </div>
</g:form>



小费



您也可以简单地params赋值:

Tip

You can also simply the params assignment:

def country = params.country ?: 'USA'
def paginationFlag = params.paginationFlag ?: 'false'

我不知道 paginationFlag 来自,但知道布尔值是有效的。

I can't tell where the paginationFlag comes from, but know that a boolean is valid.

这篇关于点击&lt; g:actionSubmit&gt;时,参数值在控制器中始终为空。按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆