validation.valid(key, object) should support null - null key - no prefix would be added

Bug #522139 reported by tomas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
play framework
Status tracked in 1.0
1.0
Fix Released
Wishlist
Nicolas Leroux
1.1
Fix Committed
Wishlist
Nicolas Leroux

Bug Description

It would be nice if there was a way not to add the prefix to the validated object:

Person person=new Person(name)
validation.validate(null, person); // would add Error with key 'name' instead of 'person.name'

Fix:ValidCheck:50
from
String fkey = key + "." + ctx.getField().getName();
to
String fkey = (key==null?"":key + ".") + ctx.getField().getName();

Changed in play:
assignee: nobody → Nicolas (nicolas-lunatech)
importance: Undecided → Medium
Revision history for this message
Nicolas Leroux (nicolas-lunatech) wrote :

I don't understand the use case I have to say. Why would you want this feature?

Revision history for this message
tomas (gugljafa) wrote :

I am not binding parameters to objects in this case, so I have an action method like
public static void foo(@Required String name){ // would add new Error with key 'name'
Person person=new Person(name);
validation.valid(person); // I have another validation in the Person class, so this would add error with key 'person.name'
validation.valid(null, person) would add error with key 'null.name' which makes no sense anyway

I want the ability to unite the two validation approaches easily

Revision history for this message
Nicolas Leroux (nicolas-lunatech) wrote :

You are right to say that it makes no sense anyway ;). But I was wondering if it was really the fix or if the valid method was abused. Fixed committed but I find it a bit weird to use valid(null, person). We should maybe come with a better solution. Anyway, thanks.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.