Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:00:15+00:00 2026-05-23T01:00:15+00:00

I’m wondering how I can populate a text box in my view from a

  • 0

I’m wondering how I can populate a text box in my view from a list in my controller, I have been searching for examples for awhile, but haven’t really found anything. I’m uncertain on how to access the text field from the view exactly, where as in Java you could do something as simple as jTextField.getText(). I’m also wondering on how to grab the text in my text box as well.

Below I’ll post some example code of what I’m 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 = {
    //get contents of text box
    //over-write props.txt with new information
}

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 straight forward, how do I access the text box when I want to populate it and save the data from it?

.

.

.

EDIT

After checking out some of the examples submitted by you guys, I have one last question.

Why does the following code act different when clicking the Load File button?

<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>

When clicking the g:submitButton dealing with loadFile it redirects me to the list gsp. However, when I click the menuButton it loads the textArea with the text from the file. The reason I ask is because with the second option, the button isn’t located where I would like it to be.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:00:15+00:00Added an answer on May 23, 2026 at 1:00 am

    Wrap your text field in form tag. This way, when you submit it, you can access your field in controller.

    <g:form controller="myController" action="saveFile">
      <g:textField name="properties"/>
      <g:submitButton name="saveFile" value="Save File" />
    </g:form>
    

    Then, you can access your properties field in controller:

    def saveFile = {
        def properties = params.properties
        // do whatever you need
    }
    

    EDIT:

    To address some of the issues that came up later in comments, I’ll try to provide some more insight.

    Let’s assume that your controller is called Drive and view (the form to submit properties) is drive/properties.gsp. If want your load button to load your properties into the text area, you can do something like this:

    def loadFile = {
       // your code here
    
       render(view: 'properties.gsp', model=[properties:propList])
    }
    

    And in your view:

    <g:form controller="drive">
      <g:textArea name="properties" value="${properties?.join("\n")}" rows="50" cols="6"/>
      <br/>
      <g:actionSubmit name="loadFile" action="loadFile" value="Load File"/>
      <g:actionSubmit name="saveFile" action="saveFile" value="Save File"/>
    </g:form>
    

    This should render your form with values from your file, each property in new line. But I didn’t test it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.