History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-1407
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Graeme Rocher
Reporter: Chris Chen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails

ValidationTagLib.hasErrors should iterate over the models and allow access to individual model elements

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

Time Tracking:
Not Specified

Patch Submitted: Yes


 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.