I am wondering how I can fill a text box in my view from a list in my controller, I searched for examples for a while, but did not find anything. I am not sure how to access the text field from the view exactly where, as in Java, you can do something as simple as jTextField.getText(). I am also wondering how to capture text in a text box.
Below I will post an example code of what I am doing.
Controller:
def loadFile = {
def propFile = "c:/props.txt"
def propMap = [:]
def propList = []
new File(propFile).eachLine { line ->
def (key,value) = line.split(':').collect { it.trim() }
propMap."$key" = "$value"
if(propMap) {
propList << propMap
propMap = [:]
}
}
}
def saveFile = {
}
View:
<g:textField name="properties"/>
<span class="menuButton"/><g:link action="loadFile" controller="myController">Load File</g:link>
<span class="menuButton"/><g:link action="saveFile" controller="myController">Save File</g:link>
So my question seems relatively straightforward, how do I access a text field when I want to populate it and save data from it?
.
.
.
EDIT
After checking some of the examples you presented, I have a final question.
Why is the following code valid when a button is clicked Load File?
<g:form controller="drive">
<g:textArea name="properties" value="${params.param1}" rows="50" cols="6"/>
<br/>
<g:submitButton name="loadFile" value="Load File"/>
<g:submitButton name="saveFile" value="Save File"/>
</g:form>
<span class="menuButton"/><g:link action="loadFile" controller="drive">Load File</g:link>
g:submitButton loadFile list gsp. , menuButton, textArea . , , , , .