English 中文(简体)
启动 Grails主计长的观点领域
原标题:Populating View fields from Controller in Grails

从对控制员采取行动的角度来看,我试图把价值输入一个领域。 我如何提及我想要装载的具体领域? 在www.txtName.Text=“John”中,它就是一个好事。 我不理解控制人员如何做到这一点,特别是如何参照外地的意见。 我曾尝试使用弹 para物体,但该物体已失效。 我知道,我正在根据我所用的印数采取行动。

Here are the relevant code snippets:

意见:

<td valign="top" class="value ${hasErrors(bean: planetInstance, field:  name ,  errors )}">
  <g:textField name="name" value="${planetInstance?.name}"/>
</td>
<td class="load">
  <g:actionSubmit value="Load" action="nameLoad"/>
</td>

管制人员:

def nameLoad = {
    // I want to reference and load the "name" textField from the view
}

希望得到任何帮助。

最佳回答

我不能从您的法典中提一下,但你可能忘记在你的控制人的行动中绘制<姓名>/代码>的可变编码。

class YourController{    
    def nameLoad = {
        def name = Planet.get(params.id).name //This can be whatever you need it to be to get the correct value assigned to the "name" variable.  Here I assume you have a domain class called "Planet" which may or may not be the case.
        return [name:name] //This is where you map key/value pairs.  The name of the key is what you will type to access the value in your view.  The value is the name of the variable you are dealing with, in this case "name".
    }
}

With the way the code above is set up Grails will assume there is a view called nameLoad in the folder YourController. So the URL will be something like:

为此,您将查阅<条码>。 类似:

可在任何标记中使用,例如<g:select> 标签,例如:

<g:select from="${name}" />
问题回答

您应能以<条码>第1款(姓名:)获取文本领域的价值。 如果你不工作,你可能会有问题。 <代码>g:text Field and g:actionSubmittags annex in a form or g:form?





相关问题
grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if ...

Error loading the grails gwt module xml

I ve installed the plugin from this article by Peter http://www.cacoethes.co.uk/blog/groovyandgrails/the-command-pattern-w.... While compile time its not able to find the module file which is present ...

Sorting Objects Based on Custom Domain Class Methods

I have a domain class, in which I ve defined some methods which give the object a score based on different algorithms (eg. popularity). I now want to retrieve a list of these objects sorted by one of ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

热门标签