In my example Rule 1 was shared between &quot;screen1.panel1.editbox1&quot; and &quot;screen1.panel1.editbox2&quot;:-<br><br><span style="font-family: courier new,monospace;">rule &quot;Rule1&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">  salience 1</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">  dialect &quot;mvel&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    when</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">      <b>ApplicationContext( context in (&quot;screen1.panel1.editbox1&quot;, &quot;screen1.panel1.editbox2&quot;) )</b></span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">

       ad : ApplicationData( age == &quot;&quot; || (  == null ))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
     then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
       ad.setReturnMsg( &quot;\n age should not be null or empty&quot; );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
end</span><br><br>This is an approach and may not be the best available; I was trying to demonstrate how your problem can be solved without having to worry about explicitly executing individual rules.For example, depending on what UI technology you are using (Swing, JSF) you could subclass the UI components and use these as facts - but such close coupling between UI and Rules may be undesirable.<br>
<br>With kind regards,<br><br>Mike<br><br><div class="gmail_quote">On 14 April 2011 03:52, Benson Fung <span dir="ltr">&lt;<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Good, Michael.<br>
<br>
&#39;context&#39; is used to distinguish which part of the UI which will be<br>
validated, right?  The customer will ask if they have 10000 rules in<br>
the rulebase.  And some of them are redundant, so they want to make<br>
some of the rules share with several part of UI, e.g.  editbox 6,<br>
editbox 7 and editbox 8 these 3 boxes&#39; value range is within 0 and<br>
600.  Therefore, Rule3 can be shared for these 3 editbox validation,<br>
right?  However, for the context variable approach, it seems Rule3<br>
cannot be shared for another editbox with same value range validation.<br>
 So these could be a key for the BRMS/Drools.<br>
<div><div></div><div class="h5"><br>
<br>
Benson<br>
<br>
2011/4/14 Michael Anstis &lt;<a href="mailto:michael.anstis@gmail.com">michael.anstis@gmail.com</a>&gt;:<br>
&gt; Sure, whenever you copy values from your UI to your model for validation you<br>
&gt; also enter a fact representing the &quot;context&quot; of the values.<br>
&gt;<br>
&gt; Using your example you have two edit boxes on one screen and your rule<br>
&gt; simply checks for the value of a single edit box; in this case the context<br>
&gt; differentiates the two.<br>
&gt;<br>
&gt; Walking your example:<br>
&gt;<br>
&gt; (1) When editbox 1 looses focus you copy the value from the dropdown and<br>
&gt; edit box 1 into your model, plus you enter a &quot;context&quot; fact stating that<br>
&gt; these values relate to that part of the UI (say &quot;screen1.panel1.editbox1&quot;).<br>
&gt; You then insert these facts into WM and call fireAllRules. The rules check<br>
&gt; the &quot;context&quot; and only execute if the values are for the (rule) applicable<br>
&gt; context. (2) Editbox 2 works in a similar way, but has a different context<br>
&gt; ((say &quot;screen1.panel1.editbox2&quot;).<br>
&gt;<br>
&gt; Have a look at Plugtree - I believe they&#39;re quite well customed to writing<br>
&gt; UIs backed with rules; salaboy or esteban (or IRC #drools) might be able to<br>
&gt; offer more practical advice.<br>
&gt;<br>
&gt; With kind regards,<br>
&gt;<br>
&gt; Mike<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On 13 April 2011 17:48, Benson Fung &lt;<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi Michael,<br>
&gt;&gt;<br>
&gt;&gt; Can you elaborate more for the uses of the ApplicationContext?  I<br>
&gt;&gt; can&#39;t follow its uses.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt; Benson<br>
&gt;&gt;<br>
&gt;&gt; 2011/4/14 Michael Anstis &lt;<a href="mailto:michael.anstis@gmail.com">michael.anstis@gmail.com</a>&gt;:<br>
&gt;&gt; &gt; Here&#39;s a quick (and probably sub-optimal way) ;)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; When you copy values from the UI to Facts for validation you also<br>
&gt;&gt; &gt; include<br>
&gt;&gt; &gt; the context of the validation.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I&#39;ve also removed the inline evals you were using.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; rule &quot;Rule1&quot;<br>
&gt;&gt; &gt;   salience 1<br>
&gt;&gt; &gt;   dialect &quot;mvel&quot;<br>
&gt;&gt; &gt;     when<br>
&gt;&gt; &gt;       ApplicationContext( context == &quot;*&quot; )<br>
&gt;&gt; &gt;       ad : ApplicationData( age == &quot;&quot; || (  == null ))<br>
&gt;&gt; &gt;     then<br>
&gt;&gt; &gt;       ad.setReturnMsg( &quot;\n age should not be null or empty&quot; );<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; rule &quot;Rule2&quot;<br>
&gt;&gt; &gt;   dialect &quot;mvel&quot;<br>
&gt;&gt; &gt;     when<br>
&gt;&gt; &gt;       ApplicationContext( context == &quot;screen1.panel1.ed&quot; )<br>
&gt;&gt; &gt;       ad : ApplicationData( $age : age != null , age != &quot;&quot; , age &lt; 0 ||<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; 100, minIssrdAge == &quot;Years&quot; )<br>
&gt;&gt; &gt;     then<br>
&gt;&gt; &gt;       ad.setReturnMsg( &quot;\nage is out of the range(i.e.  &lt; 0 and &gt; 100)&quot;<br>
&gt;&gt; &gt; );<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; rule &quot;Rule3&quot;<br>
&gt;&gt; &gt;    dialect &quot;mvel&quot;<br>
&gt;&gt; &gt;      when<br>
&gt;&gt; &gt;        ad : ApplicationData( $age : age != null , age != &quot;&quot; , age &lt;0 ||<br>
&gt;&gt; &gt; &gt;<br>
&gt;&gt; &gt; 600, minIssrdAge == &quot;Years&quot; )<br>
&gt;&gt; &gt;      then<br>
&gt;&gt; &gt;        ad.setReturnMsg( &quot;\nage is out of the range(i.e.  &lt; 0 and &gt; 600)&quot;<br>
&gt;&gt; &gt; );<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On 13 April 2011 17:19, Benson Fung &lt;<a href="mailto:benson.redhat@gmail.com">benson.redhat@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hi,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Here is the scenario :<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; If there are 2 edit boxes and 2 dropdown list at the frontend like.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; dropdown(minIssrdAge1)   editbox(age1)<br>
&gt;&gt; &gt;&gt; dropdown(minIssrdAge2)   editbox(age2)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; everytime when I lost focus the editbox(age1 or age2),  the<br>
&gt;&gt; &gt;&gt; editbox(age1 or age2) value will be validated against the following<br>
&gt;&gt; &gt;&gt; rules.<br>
&gt;&gt; &gt;&gt; i.e.  minIssrdAge1 and age1 will be validated together if lost focus<br>
&gt;&gt; &gt;&gt; the editbox age1.<br>
&gt;&gt; &gt;&gt;       minIssrdAge2 and age2 will be validated together if lost focus<br>
&gt;&gt; &gt;&gt; the editbox age2<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Rule1 is mandatory because both editbox are required field.<br>
&gt;&gt; &gt;&gt; However, editbox(age1) is only valid within the 0 and 100.  and<br>
&gt;&gt; &gt;&gt; editbox(age2) is only valid within 0 and 600.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; In other words, editbox(age1) have to be validated against Rule1 +<br>
&gt;&gt; &gt;&gt; Rule2.  However, editbox(age2) have to validated against Rule1 +<br>
&gt;&gt; &gt;&gt; Rule3.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; My question, how to design the rule attribute or at the java program<br>
&gt;&gt; &gt;&gt; side so that different editbox can be validated against different<br>
&gt;&gt; &gt;&gt; rule.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Please help.  I can&#39;t find any solution by now.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; rule &quot;Rule1&quot;<br>
&gt;&gt; &gt;&gt;        salience 1<br>
&gt;&gt; &gt;&gt;        dialect &quot;mvel&quot;<br>
&gt;&gt; &gt;&gt;        when<br>
&gt;&gt; &gt;&gt;                ad : ApplicationData( age == &quot;&quot; || (  == null ))<br>
&gt;&gt; &gt;&gt;        then<br>
&gt;&gt; &gt;&gt;                ad.setReturnMsg( &quot;\n age should not be null or empty&quot; );<br>
&gt;&gt; &gt;&gt; end<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; rule &quot;Rule2&quot;<br>
&gt;&gt; &gt;&gt;        dialect &quot;mvel&quot;<br>
&gt;&gt; &gt;&gt;        when<br>
&gt;&gt; &gt;&gt;                ad : ApplicationData( $age : age != null , age != &quot;&quot; ,<br>
&gt;&gt; &gt;&gt; minIssrdAge<br>
&gt;&gt; &gt;&gt; == &quot;Years&quot; )<br>
&gt;&gt; &gt;&gt;                eval(Integer.parseInt($age) &lt; 0) or<br>
&gt;&gt; &gt;&gt; eval(Integer.parseInt($age) &gt; 100)<br>
&gt;&gt; &gt;&gt;        then<br>
&gt;&gt; &gt;&gt;                ad.setReturnMsg( &quot;\nage is out of the range(i.e.  &lt; 0<br>
&gt;&gt; &gt;&gt; and &gt;<br>
&gt;&gt; &gt;&gt; 100)&quot; );<br>
&gt;&gt; &gt;&gt; end<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; rule &quot;Rule3&quot;<br>
&gt;&gt; &gt;&gt;        dialect &quot;mvel&quot;<br>
&gt;&gt; &gt;&gt;        when<br>
&gt;&gt; &gt;&gt;                ad : ApplicationData( $age : age != null , age != &quot;&quot; ,<br>
&gt;&gt; &gt;&gt; minIssrdAge<br>
&gt;&gt; &gt;&gt; == &quot;Years&quot; )<br>
&gt;&gt; &gt;&gt;                eval(Integer.parseInt($age) &lt; 0) or<br>
&gt;&gt; &gt;&gt; eval(Integer.parseInt($age) &gt; 600)<br>
&gt;&gt; &gt;&gt;        then<br>
&gt;&gt; &gt;&gt;                ad.setReturnMsg( &quot;\nage is out of the range(i.e.  &lt; 0<br>
&gt;&gt; &gt;&gt; and &gt;<br>
&gt;&gt; &gt;&gt; 600)&quot; );<br>
&gt;&gt; &gt;&gt; end<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>