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 4533220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:07:44+00:00 2026-05-21T14:07:44+00:00

Of course it would happen that my first Grails project presents a crazy mismatch

  • 0

Of course it would happen that my first Grails project presents a crazy mismatch between my data model and the presentation the UI designers want.

Here is a simplified statement of the problem space:

There are three ingredients in the grocery store: carrots, celery, and tomatoes. The purpose of the app is to save the user’s shopping list: how many of each to buy.

The web designers want to accomplish this with multiple HTML SELECTs, so you select from the drop-down which ingredient you want to buy, then type the quantity next to it. If you want more ingredients, you click a JavaScript link that adds more SELECTs.

The design specifies that each drop-down is the same and that the number of lines are unlimited. So you can get a form back that has 5 lines, corresponding to 3 carrots, 9 celery, 2 celery, 5 carrots, and 1 tomato.

What I “should” produce out of this is an order for 8 carrots, 11 celery, and one tomato.

Not getting into all of the arguments about why this is bad UI design, I want to understand, practically, how to map the model/controller to the view given this kind of mismatch, both to submit and ultimately edit a stored submission.

My initial idea is:

  • For inbound data, construct a fresh map in the Controller out of the parameters and some logic to add up the values correctly into three new key/value pairs, passing that new map into the bindData method instead of the request params map itself.
  • For presenting the view for edit, use an afterInterceptor to rewrite that part of the model into the correct number of these SELECTs, recognizing that my original 5-line order will become three lines when it’s presented for editing.

However, as I read about Command objects, I wonder if that would be a better approach.

I’ve read through many pages online but don’t see any solutions for this kind of MVC mismatch.

Setting aside the obvious answer (fight the designers), what is the “Grails” way to handle this?

  • 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-21T14:07:44+00:00Added an answer on May 21, 2026 at 2:07 pm

    I would think your initial idea should work. A command object would be nice to move the logic of building the domain objects out of the controller methods, but not NEEDED. One could result in easier to read code, and some easier validation if you ever add more info to your shoppingList (name, date, etc). But something without a cmd object should work and I don’t think would be wrong…

    GSP:

    <g:form .......>
    <div><g:select name="ingredient" from="${['Carrots','Celery','Tomato']}"><g:textField name="amount"/></div>
    <div><g:select name="ingredient" from="${['Carrots','Celery','Tomato']}"><g:textField name="amount"/></div>
    <div><g:select name="ingredient" from="${['Carrots','Celery','Tomato']}"><g:textField name="amount"/></div>
    <div><g:select name="ingredient" from="${['Carrots','Celery','Tomato']}"><g:textField name="amount"/></div>
    </g:form>
    

    Controller:

    def saveCart = {
      def shoppingList = [:]
      def ingredients = params.list('ingredient')
      def amounts = params.list('amount')
    
      ingredients.eachWithIndex() { obj, i ->
         if (shoppingList.containsKey(obj)) {
           shoppingList[obj] = shoppingList[obj] + amounts[i]
         } else {
           shoppingList[obj] = amt[i]
         }
      }
    
      // shoppingListshould have everything you need now
      ....
      ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know a way (of course I want to know the
I have a java application that streams raw data and draws real time plots
I'm learning about linear congruential generator in an algorithms and data structures course. After
I have a repository layer that is responsible for my data-access, which is called
I have a number of data sets that have key-value pattern - i.e. a
I'm dealing with a data structure that I haven't encountered before. The table is
Of course when developing IE is causing me headaches. This page with rounded corner
Of course, I can explain it in whole books. But I read a few
Of course we can do this, but is it alright to do so? Are
Of course I know is possible to create a file with a certain size

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.