<div dir="ltr">2013/6/7 Emmanuel Bernard <span dir="ltr">&lt;<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>&gt;</span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Ah I knew we had been working on such a problem that that it involved<br>
groups :) Let&#39;s open a specification issue and consider it for next<br>
round.<br></blockquote><div><br></div><div style>There you go: <a href="https://hibernate.atlassian.net/browse/BVAL-457">https://hibernate.atlassian.net/browse/BVAL-457</a></div><div style>�</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Note that the domain model could have use inheritance or composition to<br>
naturally enforce the presence or not of attributes depending on the<br>
model / role. It probably would be cleaner but is not always possible on<br>
existing domain models.<br></blockquote><div><br></div><div style>Yes, although I think even for newly created models it doesn&#39;t always make sense to differentiate roles of an entity via sub-classing/delegation, e.g. when the roles are dynamically retrieved from a database or similar.</div>
<div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<span class=""><font color="#888888"><br>
Emmanuel<br>
</font></span><div class=""><div class="h5"><br>
On Thu 2013-06-06 23:23, Gunnar Morling wrote:<br>
&gt; 2013/6/6 Thang Le &lt;<a href="mailto:thangmle@gmail.com">thangmle@gmail.com</a>&gt;<br>
&gt;<br>
&gt; &gt; Thanks, Emmanuel<br>
&gt; &gt;<br>
&gt; &gt; Here is a use case right off from my current work. My system is monitoring<br>
&gt; &gt; a set of devices. A device is modeled as a class named AuthorizedDevice.<br>
&gt; &gt; This class has many attributes. One of them is &#39;model&#39; which can be any<br>
&gt; &gt; value from a set of valid values: SD, TRANSNET, X710... An AuthorizedDevice<br>
&gt; &gt; also has an attribute called &#39;role&#39; which can be either REMOTE or<br>
&gt; &gt; ACCESSPOINT. Based on the value set for &#39;model&#39; &amp; &#39;role&#39;, we either do or<br>
&gt; &gt; relax specific constraints on some attributes. For example: if an<br>
&gt; &gt; AuthorizedDevice has its &#39;role&#39; set to ACCESSPOINT, we require certain<br>
&gt; &gt; attributes must not be blank. While an AuthorizedDevice has its &#39;role&#39; set<br>
&gt; &gt; to REMOTE, we relax certain constraints.<br>
&gt; &gt;<br>
&gt; &gt; I&#39;ve tried to use grouping feature of Bean Validation but it doesn&#39;t seem<br>
&gt; &gt; to help in achieving the my goal. I agree we can always write custom<br>
&gt; &gt; constraints but that means I can&#39;t reuse the built-in validation<br>
&gt; &gt; constraints from the framework (not even in the case of writing a<br>
&gt; &gt; constraint composition). And certainly, I would not want to write a custom<br>
&gt; &gt; constraints for checking NotBlank. @ScriptAssert is no better than writing<br>
&gt; &gt; your own custom constraint.<br>
&gt; &gt;<br>
&gt;<br>
&gt; Hi Thang,<br>
&gt;<br>
&gt; There is a solution if you don&#39;t mind using a feature specific to the BV<br>
&gt; reference implementation Hibernate Validator.<br>
&gt;<br>
&gt; There you can dynamically re-define the default group sequence of an object<br>
&gt; dependening on its state. So you could assign the constraints to two<br>
&gt; groups, AccessPoint.class and Remote.class and return one or the other as<br>
&gt; default group, depending on the value of the &quot;role&quot; attribute.<br>
&gt; <a href="http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#d0e2886has" target="_blank">http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#d0e2886has</a><br>
&gt; the details.<br>
&gt;<br>
&gt; Maybe we should consider to add something like this to the spec.<br>
&gt;<br>
&gt; --Gunnar<br>
&gt;<br>
</div></div><div class=""><div class="h5">&gt; Thang<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; On Thu, Jun 6, 2013 at 1:55 PM, Emmanuel Bernard &lt;<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>&gt;wrote:<br>
&gt; &gt;<br>
&gt; &gt;&gt; Hello,<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; You will have to dive into more concrete use cases. We did not add such a<br>
&gt; &gt;&gt; feature so far for a few reasons:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; - groups are offering a way to validate specific subset of constraints<br>
&gt; &gt;&gt; and solve a good chunk of non static use cases as you put it.<br>
&gt; &gt;&gt; - you can write a custom constraint (property or class level) to achieve<br>
&gt; &gt;&gt; this. That&#39;s a bit less reusable but is more readable and could be done in<br>
&gt; &gt;&gt; a more type safe way (than an EL)<br>
&gt; &gt;&gt; - you can use constraints like Hibernate Validator&#39;s @ScriptAssert that<br>
&gt; &gt;&gt; let&#39;s you write a free Groovy, EL, etc expression and be validated.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; Emmanuel<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; On 6 juin 2013, at 19:19, Thang Le &lt;<a href="mailto:thangmle@gmail.com">thangmle@gmail.com</a>&gt; wrote:<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; &gt; Hi all,<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; Validation constraints defined in Bean Validation 1.1 are mostly<br>
&gt; &gt;&gt; written and assigned in static manner. This limits us to reuse the existing<br>
&gt; &gt;&gt; constraints in value-driven manner. Could we add a new attribute<br>
&gt; &gt;&gt; &#39;executeCondition&#39; to the constrain definition? &#39;executeCondition&#39; would<br>
&gt; &gt;&gt; take an EL expression. A bean validation framework would need to evaluate<br>
&gt; &gt;&gt; the expression set in this attribute. The corresponding constraint logic<br>
&gt; &gt;&gt; only gets executed when the expression set for &#39;executeCondition&#39; is<br>
&gt; &gt;&gt; satisfied at runtime.<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; Let me know your thoughts on this suggestion.<br>
&gt; &gt;&gt; &gt;<br>
&gt; &gt;&gt; &gt; Thanks,<br>
&gt; &gt;&gt; &gt; Thang<br>
&gt; &gt;&gt; &gt; _______________________________________________<br>
&gt; &gt;&gt; &gt; beanvalidation-dev mailing list<br>
&gt; &gt;&gt; &gt; <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
&gt; &gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
&gt; &gt;&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; beanvalidation-dev mailing list<br>
&gt; &gt; <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
&gt; &gt;<br>
</div></div></blockquote></div><br></div></div>