0

I use the Spring Security UI Plugin. I dont want to use the view generated by Spring Security UI, but my own one. Therefore I want to show an error messages in my register/index view. How can I show the error messages in a list?

I would like to have this in my view:

<g:if test="${flash.message}">
    <bootstrap:alert class="alert-info">${flash.message}</bootstrap:alert>
</g:if>

When i put this lines there, no error messages are shown. But in the generated register view errors are shown.

When i put down the following code instead:

<g:eachError>
    <li>${it}</li>
</g:eachError>

Then I get alot of error messages, but cannot show them in a good way. I even cannot overwrite the messages in internatiolization API:

Field error in object 'xxx.RegisterCommand' on field 'username': rejected value []; codes [x.RegisterCommand.username.blank.error.x.RegisterCommand.username,xxx.RegisterCommand.username.blank.error.username,x.RegisterCommand.username.blank.error.java.lang.String,xxx.RegisterCommand.username.blank.error,registerCommand.username.blank.error.xxx.RegisterCommand.username,registerCommand.username.blank.error.username,registerCommand.username.blank.error.java.lang.String,registerCommand.username.blank.error,xxx.RegisterCommand.username.blank.xxx.RegisterCommand.username,xxx.RegisterCommand.username.blank.username,xxxx.RegisterCommand.username.blank.java.lang.String,xxx.RegisterCommand.username.blank,registerCommand.username.blank.xxx.RegisterCommand.username,registerCommand.username.blank.username,registerCommand.username.blank.java.lang.String,registerCommand.username.blank,blank.xxx.RegisterCommand.username,blank.username,blank.java.lang.String,blank]; arguments [username,class xxx.RegisterCommand]; default message [Die Eigenschaft [{0}] des Typs [{1}] darf nicht leer sein]

I just want to show the errors in a list.

Greetings

dildik
  • 405
  • 6
  • 16

1 Answers1

0

Render errors as follow:

<g:eachError>
    <li><g:message error="${it}"/></li>
</g:eachError>
Sergei Shushkevich
  • 1,356
  • 10
  • 14
  • Thanks! But why does my version shows up such a long message and this one just takes the messages from internationalization? – dildik Oct 10 '12 at 09:45
  • In your case you iterate over the FieldError objects and call (implicitly) toString() which is overridden in that class and returns very long string. – Sergei Shushkevich Oct 10 '12 at 09:52
  • Okay, thank you! Last question: How can i check whether they are any errors? Something like: if (errors) then showErrors – dildik Oct 10 '12 at 10:00
  • Found the solution. is the answer. :) – dildik Oct 10 '12 at 10:43
  • How can I achieve, that an error is shown together with the input field, the error occured in? – dildik Nov 01 '12 at 19:14
  • You can check individual fields for errors using "hasErrors" tag. See http://grails.org/doc/latest/ref/Tags/hasErrors.html for examples. – Sergei Shushkevich Nov 02 '12 at 07:18
  • Ive tried that, but I dont know, which bean field to use. I tried user, registerCommand (which I have from the s2ui code). When I try "command" as bean, it works, but I cannot say, that it show the field "username". Then I get no errors for that. – dildik Nov 02 '12 at 09:10