how go wanting generate default message template constraint (in jpa entity) if no such message template defined on annotation itself.
here's mean. suppose have jpa entity 'dummy':
@entity public class dummy { @column @notnull long id; } also, suppose have validationmessages.properties file containing:
dummy.id.notnull=id of dummy should not null now, if defined @notnull constraint @notnull(message={dummy.id.notnull}) work well, if wanted to generate '{dummy.id.notnull}' template on fly (using reflection) don't have write same standardized template on each , every constraint? tried using messageinterpolator class, interpolation method gets called when message attribute defined, , defeats purpose of i'm trying do.
so, make myself clear, how make validator ask chunk of code "hey, what's message constraint 'notnull' on field 'id' in class 'dummy' though has no message assigned (or rather, has default message assigned)?"
i wrong - messageinterpolator being called when no explicit message has been defined on annotation. pretty answers question. thing left figure out how field name being validated.
edit:
in end, forced implement messageinterpolator class each field passing field name in constructor , creating validator messageinterpolator when field beeing validated. don't find satisfactory, solution come with.
on note, find funny there no way trace annotated element (be field, method, class or parameter) when having access annotation instance. possible, able field name dynamically, seems "lack" of java, nothing can done.
Comments
Post a Comment