grails - 我在输入类型的文本中输入了一个值,但在params.descrption中使用空值。为什么?

标签 grails

这是gsp代码:

td align="left" class="pinkbox" style="height: 35px" width="43%">
${fieldValue(bean: bookInstance, field: "description")}<br />
input type="text" id="description" name="description" value="${fieldValue(bean: bookInstance, field: "description")}" size="30px"  />
g:link controller="conference" action="edit" id="${bookInstance.id}">Update </g:link></td>

Controller 中的常规代码:
def edit ={
  println params.description
  def bookInstance = Book.get(params.id)
  try{
    bookInstance.description = params.description
    bookInstance.save()

    redirect(action:'show',id:bookInstance.id)
  }catch(Exception e){
    flow.message ="an error occurred during update"
    redirect(action:'show',id:bookInstance.id)
  }
}

当我在文本框控件内插入一个值时,它将返回一个空值。我尝试从输入类型文本中省略值属性,但没有任何效果

最佳答案

我认为您的问题是您正在使用链接来调用 Controller 操作,并且没有提交任何参数数据。尝试按照g:link文档中的详细说明,将参数属性添加到您的g:link中:

http://www.grails.org/Tag+-+link

请注意,如果您确实想使用这样的链接,则必须使用javascript从输入值中填充参数。

或者,也许更正确,使用表格。你应该尝试像

<g:form controller='thecontroller' method='edit'>    
  <g:textarea name="" value="" type="text"></g:textarea>
   ... more fields here including  a submit ...
</g:form>

如果您确实希望将“按钮”作为链接,则可以使用javascript使其提交表单。但是,按预期使用该表格可能是最好的。 Grails与约定有关...

关于grails - 我在输入类型的文本中输入了一个值,但在params.descrption中使用空值。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4352923/

相关文章:

java - Quartz Scheduler 在 war 文件中不起作用

csv - 是否有任何插件可以解析Grails 3.1.1发送到后端的csv文件?

hibernate - 如何在 grails ORM 中建模学生-类(class)关系?多对多关系

grails - grails 2.4.4:如何在服务方法中立即提交每个插入(也称为保存)?

unit-testing - 可以以编程方式生成 jpeg 图像吗?

unit-testing - 如何使用多个私有(private)插件运行 Grails 应用程序的所有单元测试

grails - javax.servlet.ServletException : Filter [sitemesh]: could not be initialized when deploying grails 2. 11 应用程序到 WebSphere 8.5 自由配置文件?

grails - 使用 Google OAuth API 检索出生日期和婚姻状况

grails - 没有为自定义操作调用Grails筛选器

grails - 从微服务中获取数据以保证其正常运行