【问题标题】:Passing the foreign key to the edit / delete view grails将外键传递给编辑/删除视图 grails
【发布时间】:2012-08-31 05:01:27
【问题描述】:

我有一组 stream 视频,其外键为它们所属的 district。 但是,然后我点击editdelete 按钮,我得到了;

Error 2012-08-30 23:51:16,424 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver  - MissingMethodException occurred when processing request: [GET] /ctv/stream/list
No signature of method: ctv.Stream.findAllByDistrict() is applicable for argument types: () values: []
Possible solutions: findAllByDistrict([Ljava.lang.Object;). Stacktrace follows:
Message: No signature of method: ctv.Stream.findAllByDistrict() is applicable for argument types: () values: []
Possible solutions: findAllByDistrict([Ljava.lang.Object;)

问题是因为

<g:form>
  <g:hiddenField name="id" value="${streamInstance?.id}" />
  <span class="button"><g:actionSubmit class="edit" action="edit" id="${params['district']}" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
  <span class="button"><g:actionSubmit class="delete" action="delete" id="${params['district']}" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
</g:form>

我正在尝试将district id 发送到edit 页面,但我做不到。有人可以帮我吗?假设district=10,那么我需要通过&lt;g:actionSubmit&gt;标签传递值10。我怎么能这样做?

【问题讨论】:

  • 向我们展示触发编辑操作的控制器代码。还是您使用static scaffold = true
  • @nickdos:我用static scaffold = true

标签: grails groovy


【解决方案1】:

我认为actionSubmit 标签支持 id 参数。它只支持行动和价值。

您必须将地区 id 放在隐藏字段中

<g:hiddenField name="district" value="${params['district']}" />

【讨论】:

  • 那么你知道如何从另一个视图访问隐藏字段吗?
  • 有时params['district'] 为空。
  • 用firebug检查表单源以确保隐藏字段正确填写
【解决方案2】:

使用简单的 g:link &lt;g:link action="edit" id="${streamInstance.id}" &gt; 这里不需要 g:form。 还要检查您的控制器设置。

class MakeAppController {
static allowedMethods = [ update: "POST", delete: "GET",save: "GET"]

因为 Grails 框架允许在控制器中检查请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    相关资源
    最近更新 更多