|
I have some issues around editing properties inside child
collections: 1.
Validation only cascades into child collections if “belongsTo”
is set. I think that it ought to cascade if Hibernate cascade is set to “all”
or “all-delete-orphan”. a. I
think this is an issue with GrailsDomainClassValidator.isOwningInstance
i.
I think that HibernateDomainClassValidator should
override this method and return true if Hibernate cascade is set to anything
>= “save” b. Does
anyone disagree? c. If
I were to submit a patch to correct this, would it be accepted, or are people
relying on this behaviour? 2.
When validation cascades into a List of children, the
error path is set to “collectionName.property” rather than “collectionName[index].property”. a. This
differs from the databinding errors, which will be assigned at “children[0].ageYears”
if you post a non-integer to that property path. b. For
example, run the attached app, go to edit a parent and enter “foo”
for a child’s age – you’ll see that the correct textbox is
highlighted in red c. But
for grails validation, the errors are assigned a property path of “children.ageYears”,
for all indexes d. For
example, run the attached app, go to edit a parent and enter “-1”
for a child’s age – you’ll see that no textboxes are
highlighted in red e. I
think that this is a bug in GrailsDomainClassValidator.cascadeToAssociativeProperty
i.
I think that it should push the index onto the property
path for List typed properties f.
Does anyone disagree? g. If
I were to submit a patch to correct this, would it be accepted, or are people
relying on this behaviour? 3.
The “fieldValue” tag doesn’t support
indexed properties a. For
example, I’d like to use a tag like: <g:textField name="children[${ii}].ageYears"
value='${fieldValue(bean:parentInstance,field:"children[${ii}].ageYears")}'
/> b. But
this doesn’t work, so I have to use code like: <%-- note that
you can't use g:set for rejectedVal, since it coerces null into ""
--%> <% def
rejectedVal =
parentInstance.errors?.getFieldError("children[$ii].ageYears")?.rejectedValue
%> <g:textField
name="children[${ii}].ageYears" value='${rejectedVal
== null ? parentInstance.children[ii].ageYears : rejectedVal}' /> c. I
think this is a bug in ValidationTagLib.fieldValue d. I’m
not sure how to fix it though. It almost needs to eval() the given field string,
but that would be too dangerous. Any ideas? What does Spring do? I have also noticed these related, but less urgent issues: 4.
Why doesn’t the scaffolding use “fieldValue”
for the value in g:textField? a. It
simply uses model?.property, which means that if you type a value in which can’t
be cast to the correct type, then your data is lost, instead of being presented
back to you with validation errors.
i.
I think that it should look like: <g:textField
name="ageYears" value="${fieldValue(bean:model,field:'property')}"
/> b. If
I were to submit a patch to correct this, would it be accepted, or are people
relying on this behaviour? 5.
Why does <g:set> coerce null values into the
empty string? I’ve attached a simple project which demonstrates all
the above issues. Thanks, Rich softwire Softwire
Technology Limited. Registered in England no. 3824658. Registered Office : 13
Station Road, London N3 2SB softwire Softwire
Technology Limited. Registered in England no. 3824658. Registered Office : 13
Station Road, London N3 2SB --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
> 1. Validation only cascades into child collections if “belongsTo” is
> set. I think that it ought to cascade if Hibernate cascade is set to “all” > or “all-delete-orphan”. > > a. I think this is an issue with > GrailsDomainClassValidator.isOwningInstance > > i. I > think that HibernateDomainClassValidator should override this method and > return true if Hibernate cascade is set to anything >= “save” > > b. Does anyone disagree? I think this is a valid argument, but it does constitute a breaking change. It is perhaps something we might consider for Grails 1.4. > 2. When validation cascades into a List of children, the error path is > set to “collectionName.property” rather than > “collectionName[index].property”. > > a. This differs from the databinding errors, which will be assigned at > “children[0].ageYears” if you post a non-integer to that property path. > > b. For example, run the attached app, go to edit a parent and enter > “foo” for a child’s age – you’ll see that the correct textbox is highlighted > in red > > c. But for grails validation, the errors are assigned a property path > of “children.ageYears”, for all indexes > > d. For example, run the attached app, go to edit a parent and enter > “-1” for a child’s age – you’ll see that no textboxes are highlighted in red > > e. I think that this is a bug in > GrailsDomainClassValidator.cascadeToAssociativeProperty Sounds like a bug to me, but again it would be a breaking change. In this particular case I would consider fixing it in a patch release. > 3. The “fieldValue” tag doesn’t support indexed properties > > a. For example, I’d like to use a tag like: > > <g:textField name="children[${ii}].ageYears" > value='${fieldValue(bean:parentInstance,field:"children[${ii}].ageYears")}' > /> > > b. But this doesn’t work, so I have to use code like: > > <%-- note that you can't use g:set for rejectedVal, since it coerces null > into "" --%> > > <% def rejectedVal = > parentInstance.errors?.getFieldError("children[$ii].ageYears")?.rejectedValue > %> > > <g:textField name="children[${ii}].ageYears" > > value='${rejectedVal == null ? parentInstance.children[ii].ageYears : > rejectedVal}' /> > > c. I think this is a bug in ValidationTagLib.fieldValue > > d. I’m not sure how to fix it though. It almost needs to eval() the > given field string, but that would be too dangerous. Any ideas? What does > Spring do? This is something that could be looked at. I know Rob Fletcher was working with indexed properties, so he may have an idea for what to do. > I have also noticed these related, but less urgent issues: > > 4. Why doesn’t the scaffolding use “fieldValue” for the value in > g:textField? > > a. It simply uses model?.property, which means that if you type a > value in which can’t be cast to the correct type, then your data is lost, > instead of being presented back to you with validation errors. > i. I > think that it should look like: > > <g:textField name="ageYears" > value="${fieldValue(bean:model,field:'property')}" /> This is possibly an oversight. To be honest, I think we should consider rolling the BeanFields plugin into core and updating the scaffolding to use it. > b. If I were to submit a patch to correct this, would it be accepted, > or are people relying on this behaviour? I think you're safe to update the scaffolding as the long as the result works :) > 5. Why does <g:set> coerce null values into the empty string? I don't know. It may not be intentional. It seems wrong to me, but there may be good arguments for doing the coercion. Peter --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I concur with Richard on the two issues below, and hope they will be
fixed for 1.4. There's a JIRA[1] for the second. Is there one for the first, too? If it's a breaking change, does it need to go into 1.4.0? [1] http://jira.codehaus.org/browse/GRAILS-3630 On 2010-10-07 22:13 , Peter Ledbrook wrote: >> 2. When validation cascades into a List of children, the error path is >> set to “collectionName.property” rather than >> “collectionName[index].property”. >> >> a. This differs from the databinding errors, which will be assigned at >> “children[0].ageYears” if you post a non-integer to that property path. >> >> b. For example, run the attached app, go to edit a parent and enter >> “foo” for a child’s age – you’ll see that the correct textbox is highlighted >> in red >> >> c. But for grails validation, the errors are assigned a property path >> of “children.ageYears”, for all indexes >> >> d. For example, run the attached app, go to edit a parent and enter >> “-1” for a child’s age – you’ll see that no textboxes are highlighted in red >> >> e. I think that this is a bug in >> GrailsDomainClassValidator.cascadeToAssociativeProperty > Sounds like a bug to me, but again it would be a breaking change. In > this particular case I would consider fixing it in a patch release. > >> 3. The “fieldValue” tag doesn’t support indexed properties >> >> a. For example, I’d like to use a tag like: >> >> <g:textField name="children[${ii}].ageYears" >> value='${fieldValue(bean:parentInstance,field:"children[${ii}].ageYears")}' >> /> >> >> b. But this doesn’t work, so I have to use code like: >> >> <%-- note that you can't use g:set for rejectedVal, since it coerces null >> into "" --%> >> >> <% def rejectedVal = >> parentInstance.errors?.getFieldError("children[$ii].ageYears")?.rejectedValue >> %> >> >> <g:textField name="children[${ii}].ageYears" >> >> value='${rejectedVal == null ? parentInstance.children[ii].ageYears : >> rejectedVal}' /> >> >> c. I think this is a bug in ValidationTagLib.fieldValue >> >> d. I’m not sure how to fix it though. It almost needs to eval() the >> given field string, but that would be too dangerous. Any ideas? What does >> Spring do? > This is something that could be looked at. I know Rob Fletcher was > working with indexed properties, so he may have an idea for what to > do. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I couldn't find a JIRA for the first issue, so I created
http://jira.codehaus.org/browse/GRAILS-7321 On 2011-03-01 16:13 , J. David Beutel wrote: > I concur with Richard on the two issues below, and hope they will be > fixed for 1.4. There's a JIRA[1] for the second. Is there one for > the first, too? If it's a breaking change, does it need to go into > 1.4.0? > > [1] http://jira.codehaus.org/browse/GRAILS-3630 > > > On 2010-10-07 22:13 , Peter Ledbrook wrote: >>> 2. When validation cascades into a List of children, the error >>> path is >>> set to “collectionName.property” rather than >>> “collectionName[index].property”. >>> >>> a. This differs from the databinding errors, which will be >>> assigned at >>> “children[0].ageYears” if you post a non-integer to that property path. >>> >>> b. For example, run the attached app, go to edit a parent and >>> enter >>> “foo” for a child’s age – you’ll see that the correct textbox is >>> highlighted >>> in red >>> >>> c. But for grails validation, the errors are assigned a >>> property path >>> of “children.ageYears”, for all indexes >>> >>> d. For example, run the attached app, go to edit a parent and >>> enter >>> “-1” for a child’s age – you’ll see that no textboxes are >>> highlighted in red >>> >>> e. I think that this is a bug in >>> GrailsDomainClassValidator.cascadeToAssociativeProperty >> Sounds like a bug to me, but again it would be a breaking change. In >> this particular case I would consider fixing it in a patch release. >> >>> 3. The “fieldValue” tag doesn’t support indexed properties >>> >>> a. For example, I’d like to use a tag like: >>> >>> <g:textField name="children[${ii}].ageYears" >>> value='${fieldValue(bean:parentInstance,field:"children[${ii}].ageYears")}' >>> >>> /> >>> >>> b. But this doesn’t work, so I have to use code like: >>> >>> <%-- note that you can't use g:set for rejectedVal, since it coerces >>> null >>> into "" --%> >>> >>> <% def rejectedVal = >>> parentInstance.errors?.getFieldError("children[$ii].ageYears")?.rejectedValue >>> >>> %> >>> >>> <g:textField name="children[${ii}].ageYears" >>> >>> value='${rejectedVal == null ? >>> parentInstance.children[ii].ageYears : >>> rejectedVal}' /> >>> >>> c. I think this is a bug in ValidationTagLib.fieldValue >>> >>> d. I’m not sure how to fix it though. It almost needs to eval() >>> the >>> given field string, but that would be too dangerous. Any ideas? What >>> does >>> Spring do? >> This is something that could be looked at. I know Rob Fletcher was >> working with indexed properties, so he may have an idea for what to >> do. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
