
|
If you were logged in you would be able to see more operations.
|
|
|
Grails
Created: 20/Jul/07 05:24 PM
Updated: 20/Jul/07 05:24 PM
|
|
| Component/s: |
TagLib
|
| Affects Version/s: |
0.5.6
|
| Fix Version/s: |
None
|
|
currently, ValidationTagLib's hasErrors closure does not support the model attribute very well. For instance, the following code:
<g:hasErrors model="[a:a, b:b]">
<g:eachError bean="${<here is the problem>}">${it.defaultMessage}</g:eachError>
</g:hasErrors>
The problem with this code is that the body of <g:hasErrors> will be iterated over twice (because we have 2 objects in our model). The inner body does not have access to the current model object that's being iterated over. The relevant code that's in question is here:
def hasErrors = { attrs, body ->
//.................................
if(errors) {
if(attrs['field']) {
if(errors.hasFieldErrors(attrs['field'])) {
out << body()
}
}
else {
out << body()
}
}
}
}
The code does not pass the current error object being iterated over. Hence, I am unable to access and print out the right error object codes.
The fix is to pass the current error object being iterated over to the body for use, as follows:
def hasErrors = { attrs, body ->
//.................................
if(errors) {
if(attrs['field']) {
if(errors.hasFieldErrors(attrs['field'])) {
out << body(errors)
}
}
else {
out << body(errors)
}
}
}
}
This will allow the body to do something like this:
<g:hasErrors model="[a:a, b:b]">
<g:eachError bean="${it}">${it.defaultMessage}</g:eachError>
</g:hasErrors>
Now the eachError can properly access the current error object in the model and display each error.
|
|
Description
|
currently, ValidationTagLib's hasErrors closure does not support the model attribute very well. For instance, the following code:
<g:hasErrors model="[a:a, b:b]">
<g:eachError bean="${<here is the problem>}">${it.defaultMessage}</g:eachError>
</g:hasErrors>
The problem with this code is that the body of <g:hasErrors> will be iterated over twice (because we have 2 objects in our model). The inner body does not have access to the current model object that's being iterated over. The relevant code that's in question is here:
def hasErrors = { attrs, body ->
//.................................
if(errors) {
if(attrs['field']) {
if(errors.hasFieldErrors(attrs['field'])) {
out << body()
}
}
else {
out << body()
}
}
}
}
The code does not pass the current error object being iterated over. Hence, I am unable to access and print out the right error object codes.
The fix is to pass the current error object being iterated over to the body for use, as follows:
def hasErrors = { attrs, body ->
//.................................
if(errors) {
if(attrs['field']) {
if(errors.hasFieldErrors(attrs['field'])) {
out << body(errors)
}
}
else {
out << body(errors)
}
}
}
}
This will allow the body to do something like this:
<g:hasErrors model="[a:a, b:b]">
<g:eachError bean="${it}">${it.defaultMessage}</g:eachError>
</g:hasErrors>
Now the eachError can properly access the current error object in the model and display each error.
|
Show » |
| There are no comments yet on this issue.
|
|