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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:55:38+00:00 2026-06-10T20:55:38+00:00

Errors e.g. with bad user input can not always be reasonably checked using domain

  • 0

Errors e.g. with bad user input can not always be reasonably checked using domain or command object validation.

E.g. when creating a “forgot password” functionality, I want to show an adequate message if the user enters a username which is not present in the database. So the controller action does something like this

...
def user = User.find{name==uname}
if(!user) {
    // user not found in db, output error and render view again
    render view: 'forgotPassword'
    return
}
// do reset password stuff
...

What should I do to display the error in the view within the <g:hasErros> tag?

flash.message (as the generated controllers/views do it) does not seem right to me, because I am not merely displaying an info message, but an error message. That’s why I think the message should be handled by the <g:hasErros> tag and displayed like a domain validation error. (To the user, it is the same feedback level: “did not work due to bad input”.

Creating a @Validateable command object does not seem right, too. IMHO, checking a value against the database is not actually the responsibility of validation within a command object? Or is it? Then it seems to be a little too complex to me.

So what is the best way to go? Other frameworks (e.g. Wicket) provide distinct methods like error(String msg) and info(String msg) which allow easy handling of feedback messages in the view. Is there a similar concept in Grails, which I just have not found yet?

  • 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-06-10T20:55:40+00:00Added an answer on June 10, 2026 at 8:55 pm

    flash is just a Map and you can put whatever you want in it – strings, numbers, objects, etc. It’s convenient since it only lasts one request, so it only temporarily pollutes the session. The convention in the generated GSPs is to use the message key, but it’s just a convention.

    If you want to store another message, store it in a different key:

    flash.warning = '...'
    

    or

    flash.error = '...'
    

    and retrieve it in the GSP like the other message.

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

Sidebar

Related Questions

I am using jAlert to display an alert on bad input. The popup displays
I'm getting a bad error. When I call delete on an object at the
I am currently facing an error called Bad Base64Coder input character at ... Here
How can I get mcc to recognize imports from user-provided Java libraries, or to
Part of my site requires user to input URLs, but in case they type
sorry if my english bad.. let's to the point here my HTML: <input type=text
Theoretically, the end user should never see internal errors. But in practice, theory and
i'll like to print in a web page, text-user input, but it could have
I'm getting weird EXC_BAD_ACCESS errors. I thought that I didn't need to retain objects
I'm getting a 400 Bad Request error when deploying my Backbone.js/node.js app to Heroku.

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.