<div dir="ltr">2013/6/6 Thang Le <span dir="ltr">&lt;<a href="mailto:thangmle@gmail.com" target="_blank">thangmle@gmail.com</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">
<div dir="ltr"><div><div><div>Thanks, Emmanuel<br><br></div>Here is a use case right 
off from my current work. My system is monitoring a set of devices. A 
device is modeled as a class named AuthorizedDevice. This class has many
 attributes. One of them is &#39;model&#39; which can be any value from a set of
 valid values: SD, TRANSNET, X710... An AuthorizedDevice also has an 
attribute called &#39;role&#39; which can be either REMOTE or ACCESSPOINT. Based
 on the value set for &#39;model&#39; &amp; &#39;role&#39;, we either do or relax 
specific constraints on some attributes. For example: if an 
AuthorizedDevice has its &#39;role&#39; set to ACCESSPOINT, we require certain 
attributes must not be blank. While an AuthorizedDevice has its &#39;role&#39; 
set to REMOTE, we relax certain constraints.<br>
<br></div>I&#39;ve tried to use grouping feature of Bean Validation but it 
doesn&#39;t seem to help in achieving the my goal. I agree we can always 
write custom constraints but that means I can&#39;t reuse the built-in 
validation constraints from the framework (not even in the case of 
writing a constraint composition). And certainly, I would not want to 
write a custom constraints for checking NotBlank. @ScriptAssert is no 
better than writing your own custom constraint.</div></div></blockquote><div><br></div><div style>Hi Thang,</div><div style><br></div><div style>There is a solution if you don&#39;t mind using a feature specific to the BV reference implementation Hibernate Validator.</div>
<div style><br></div><div style>There you can dynamically re-define the default group sequence of an object dependening on its state. So you could assign the constraints to two groups, AccessPoint.class and Remote.class and return one or the other as default group, depending on the value of the &quot;role&quot; attribute. <a href="http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#d0e2886">http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#d0e2886</a> has the details.</div>
<div style><br></div><div style>Maybe we should consider to add something like this to the spec.</div><div style><br></div><div style>--Gunnar</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">
<div dir="ltr"><div><div><div><img></div></div><span class=""><font color="#888888"><span><font color="#888888">Thang<br>
</font></span></font></span></div><div class="im"><div><span><font color="#888888">
<br></font></span></div><span></span><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 6, 2013 at 1:55 PM, Emmanuel Bernard <span dir="ltr">&lt;<a href="mailto:emmanuel@hibernate.org" target="_blank">emmanuel@hibernate.org</a>&gt;</span> wrote:<br>

<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">Hello,<br>
<br>
You will have to dive into more concrete use cases. We did not add such a feature so far for a few reasons:<br>
<br>
- groups are offering a way to validate specific subset of constraints and solve a good chunk of non static use cases as you put it.<br>
- you can write a custom constraint (property or class level) to achieve this. That&#39;s a bit less reusable but is more readable and could be done in a more type safe way (than an EL)<br>
- you can use constraints like Hibernate Validator&#39;s @ScriptAssert that let&#39;s you write a free Groovy, EL, etc expression and be validated.<br>
<br>
Emmanuel<br>
<div><div><br>
On 6 juin 2013, at 19:19, Thang Le &lt;<a href="mailto:thangmle@gmail.com" target="_blank">thangmle@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Hi all,<br>
&gt;<br>
&gt; Validation constraints defined in Bean Validation 1.1 are mostly written and assigned in static manner. This limits us to reuse the existing constraints in value-driven manner. Could we add a new attribute &#39;executeCondition&#39; to the constrain definition? &#39;executeCondition&#39; would take an EL expression. A bean validation framework would need to evaluate the expression set in this attribute. The corresponding constraint logic only gets executed when the expression set for &#39;executeCondition&#39; is satisfied at runtime.<br>


&gt;<br>
&gt; Let me know your thoughts on this suggestion.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Thang<br>
</div></div>&gt; _______________________________________________<br>
&gt; beanvalidation-dev mailing list<br>
&gt; <a href="mailto:beanvalidation-dev@lists.jboss.org" target="_blank">beanvalidation-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/beanvalidation-dev</a><br></blockquote></div><br></div></div>