<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>From: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Emmanuel Bernard <<a href="mailto:emmanuel.bernard@JBOSS.COM">emmanuel.bernard@JBOSS.COM</a>></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Date:<span class="Apple-converted-space"> </span></b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"> June 15, 2009 17:57:48<span class="Apple-converted-space"> </span>EDT</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:JSR-303-EG@JCP.ORG">JSR-303-EG@JCP.ORG</a></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Subject: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><b>Re: constraint level payload</b></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" color="#000000" style="font: 12.0px Helvetica; color: #000000"><b>Reply-To: </b></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Java Community Process JSR #303 Expert List <<a href="mailto:JSR-303-EG@JCP.ORG">JSR-303-EG@JCP.ORG</a>></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div> </div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Done<div><a href="http://people.redhat.com/~ebernard/validation/#constraintsdefinitionimplementation-constraintdefinition-payload">http://people.redhat.com/~ebernard/validation/#constraintsdefinitionimplementation-constraintdefinition-payload</a></div><div><br></div><div>Pleaase have a look and let me know what you think. I'm not a big fan of forcing this noew attribute on everybody's constraint but I don't see muc more possibilities.</div><div><br></div><div><span class="Apple-style-span" style="font-family: sans-serif; font-size: 14px; "><div class="titlepage" style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><div style="font-family: sans-serif; font-size: 14px; "><h4 class="title" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 51, 153); margin-top: 10px; padding-top: 5px; font-weight: bold; ">2.1.1.3. payload</h4></div></div><div style="font-family: sans-serif; font-size: 14px; "></div></div><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">Every constraint annotation must define a <tt class="literal" style="font-family: monospace; font-size: 14px; color: rgb(17, 17, 17); ">payload</tt> element that specifies which payload the constraint declaration is associated with.</p><pre class="programlisting" style="font-family: monospace; font-size: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(244, 244, 244); width: auto; "> Class<? extends ConstraintPayload>[] payload() default {};</pre><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">The default value must be an empty array.</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">Each attachable payload extends <tt class="classname" style="font-family: monospace; font-size: 14px; color: rgb(17, 17, 17); ">ConstraintPayload</tt>.</p><pre class="programlisting" style="font-family: monospace; font-size: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(244, 244, 244); width: auto; ">/**
* Payload type that can be attached to a given
* constraint declaration.
* Payloads are typically used to carry on metadata information
* consumed by a validation client.
*
* Use of payloads is not considered portable.
*
* @author Emmanuel Bernard
* @author Gerhard Petracek
*/
public interface ConstraintPayload {
}</pre><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">Payloads are typically used by validation clients to associate some metadata information to a given constraint declaration. Payloads are typically non portable. Describing payloads as interface extensions as opposed to a string based approach allows an easier and more type-safe approach.</p><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">One use case for payload shown in <a href="http://people.redhat.com/~ebernard/validation/#example-payload" title="Example 2.1. Use of payload to associate severity to a constraint" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); ">Example 2.1, “Use of payload to associate severity to a constraint”</a> is to associate a severity to a constraint. This severity can be exploited by a presentation framework to adjust how a constraint failure is displayed.</p><div class="example" style="font-family: sans-serif; font-size: 14px; "><a name="example-payload" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); "></a><p class="title" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); margin-top: 10px; padding-top: 5px; font-weight: bold; "><b style="font-family: sans-serif; font-size: 14px; ">Example 2.1. Use of payload to associate severity to a constraint</b></p><pre class="programlisting" style="font-family: monospace; font-size: 14px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(244, 244, 244); width: auto; ">package com.acme.severity;
public class Severity {
public static class Info extends ConstraintPayload {};
public static class Error extends ConstraintPayload {};
}
public class Address {
@NotNull(message="would be nice if we had one", payload=Severity.Info.class)
public String getZipCode() {...}
@NotNull(message="the city is mandatory", payload=Severity.Error.class)
String getCity() {...}
}</pre></div><p style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 0); ">The <tt class="literal" style="font-family: monospace; font-size: 14px; color: rgb(17, 17, 17); ">payload</tt> information can be retrieved from error reports via <tt class="classname" style="font-family: monospace; font-size: 14px; color: rgb(17, 17, 17); ">ConstraintViolation</tt> objects (see <a href="http://people.redhat.com/~ebernard/validation/#validationapi-constraintviolation" title="4.2. ConstraintViolation" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); ">Section 4.2, “ConstraintViolation”</a>) or using the metadata API via<tt class="classname" style="font-family: monospace; font-size: 14px; color: rgb(17, 17, 17); ">ConstraintDescriptor</tt> objects (see <a href="http://people.redhat.com/~ebernard/validation/#constraintmetadata-constraintdescriptor" title="5.5. ConstraintDescriptor" style="font-family: sans-serif; font-size: 14px; color: rgb(0, 0, 204); ">Section 5.5, “ConstraintDescriptor”</a>).</p></span></div><div><br><div><div>On May 29, 2009, at 04:49, Emmanuel Bernard wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">We have had a few discussions around having a payload on constraints that could be consumed by client frameworks.<div><br></div><div>There are 4 competing solutions:</div><div><br></div><div>#1 Nothing</div><div>The argument would be that it's not needed and hence we don't need any payload.</div><div>On that subject what are the use cases for such a payload. Please be as specific as possible.</div><div><br></div><div> - We have identified Error / Warn modes which I argued can be solved by groups. I also argued that groups and modes are *not* orthogonal to groups and hence would not lead to a group explosion. Can someone bring a real use case showing groups and modes as orthogonal? (something more substantial than Group1</div><div><br></div><div> - Sebastian, what were the other use cases you had in mind when you wanted the @param approach</div><div><br></div><div>#2 keep it open for later</div><div>we could reserve the "payload" or "parameter" attribute name and use it for a next rev of this spec.</div><div><br></div><div>#3 the string based approach</div><div>Sebastian's proposal</div><div><br></div><div>@NotNull(params={@Param(key="prio";value="1"),@Param(key="severity";value="3")})<br>String myfield;</div><div><br></div><div>I personally don't like this approach as it is very verbose and totally unsafe. But it has the advantage of allowing parameters very easily.</div><div><br></div><div>#4 the interface based approach</div><div><br></div><div>(Part of) Gerhard's proposal</div><div><br></div><div>interface javax.validation.ValidationParameter {}</div><div><br></div><div>//framework classes</div><div><div>interface com.acme.ViolationSeverity extends ValidationParameter {</div><div> F<span class="Apple-style-span" style="font-family: 'courier new'; font-size: 10px; ">acesMessage.Severity();</span></div><div> M<span class="Apple-style-span" style="font-family: 'courier new'; font-size: 10px; ">essageType postfix();</span></div><div>}</div><div><br></div><div>class com.acme.WarnSeverity implements ViolationSeverity {</div><div><font class="Apple-style-span" face="'courier new'" size="2"><span class="Apple-style-span" style="font-family: Helvetica; font-size: 12px; "><div> F<span class="Apple-style-span" style="font-family: 'courier new'; font-size: 10px; ">acesMessage.Severity() { return acesMessage.SEVERITY_WARN; }</span></div><div> M<span class="Apple-style-span" style="font-family: 'courier new'; font-size: 10px; ">essageType postfix() { return MessageType.WARN;}</span></div></span></font></div><div>}</div></div><div><br></div><div>//user code</div><div>@NotNull(params=WarnSeverity.class)</div><div><br></div><div>Pros:</div><div>much cleaner on the client code</div><div>type safe ont he client code</div><div><br></div><div>Cons:</div><div>much more verbose to define a new kind of parameter</div><div>untype safe when the value is read by the framework (so is #3) </div><div> ValidationParameter[] params = constraintViolation.getAnnotation().params(); if (params[0] instanceof ViolationSeverity) {};</div><div>it creates a compile time dependency on the targeted framework</div><div>no runtime dependency but if the framework is not here, the constraint annotation will not be visible</div></div></blockquote></div><br></div></div></blockquote></div><br></body></html>