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

  • Home
  • SEARCH
  • 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 6899665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:27:00+00:00 2026-05-27T07:27:00+00:00

I have a Person class with two properties: name and address . I want

  • 0

I have a Person class with two properties: name and address. I want to build a GSP page which allows for 10 users to be created at one time. This is how I’m implementing it and was wondering if there is a better way:

First, make 20 text boxes in the GSP page – 10 with someperson.name and 10 with someperson.address field names (make these in a loop or code them all individually, doesn’t matter).

Second, process the submitted data in the controller. The someperson object has the submitted data, but in a not-so-nice structure ([name: ['Bob', 'John'], address: ['Address 1', 'Address 2']]), so I call transpose() on this to be able to access name, address pairs.

Then, build a list of Person objects using the pairs obtained from the previous step and validate/save them.

Finally, if validation fails (name cannot be null) then do something… don’t know what yet! I’m thinking of passing the collection of Person objects to the GSP where they are iterated using a loop and if hasErrors then show them… Don’t know how to highlight the fields which failed validation…

So, is there a better way (I should probably ask WHAT IS the better way)?

  • 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-27T07:27:01+00:00Added an answer on May 27, 2026 at 7:27 am

    You should use Grails’ data-binding support by declaring a command object like this

    class PersonCommand {
    
      List<Person> people = []
    }
    

    If you construct your form so that the request parameters are named like this:

    person[0].name=bob
    person[0].address=england
    person[1].name=john
    person[1].address=ireland
    

    The data will be automatically bound to the personCommand argument of this controller action

    class MyController {
    
      def savePeople = {PersonCommand personCommand->
    
      }
    }
    

    If you call personCommand.validate() it might in turn call validate() on each Person in people (I’m not sure). If it doesn’t you can do this yourself by calling

    boolean allPersonsValid = personCommand.people.every {it.validate()}
    

    At this point you’ll know whether all Person instances are valid. If they are not, you should pass the PersonCommand back to the GSP and you can use the Grails tags:

    • <g:eachError>
    • <g:hasErrors>
    • <g:renderErrors>

    to highlight the fields in errors. If you’re not exactly sure how to use these tags to do the highlight, I suggest you run grails generate-all for a domain class and look at the GSP code it generates.

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

Sidebar

Related Questions

I have a class Person and a class Name. Name contains two Strings firstName
I have a Person class (annotated with @XmlRootElement ) in Java with two properties
I have a model named Person. It has two properties - name and parent_person_id
I have a simple domain class with two properties. For example: class Person {
I have these two classes public class Person { } public class Company {
I have a Person class which has a String collection of aliases representing additional
I have two classes (Person and Address) that i need to send via wcf,
I have an array filled with instances of a custom class which contains two
i have the two classes Person and Attribut, in short: @Entity @Indexed @Table(name=persons) public
I have class Person as following : class Person { char* name; int age;

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.