Sure, whenever you copy values from your UI to your model for validation you also enter a fact representing the "context" of the values.
Using your example you have two edit boxes on one screen and your rule simply checks for the value of a single edit box; in this case the context differentiates the two. Walking your example: (1) When editbox 1 looses focus you copy the value from the dropdown and edit box 1 into your model, plus you enter a "context" fact stating that these values relate to that part of the UI (say "screen1.panel1.editbox1"). You then insert these facts into WM and call fireAllRules. The rules check the "context" and only execute if the values are for the (rule) applicable context. (2) Editbox 2 works in a similar way, but has a different context ((say "screen1.panel1.editbox2"). Have a look at Plugtree - I believe they're quite well customed to writing UIs backed with rules; salaboy or esteban (or IRC #drools) might be able to offer more practical advice. With kind regards, Mike On 13 April 2011 17:48, Benson Fung <benson.red...@gmail.com> wrote: > Hi Michael, > > Can you elaborate more for the uses of the ApplicationContext? I > can't follow its uses. > > > Thanks > Benson > > 2011/4/14 Michael Anstis <michael.ans...@gmail.com>: > > Here's a quick (and probably sub-optimal way) ;) > > > > When you copy values from the UI to Facts for validation you also include > > the context of the validation. > > > > I've also removed the inline evals you were using. > > > > rule "Rule1" > > salience 1 > > dialect "mvel" > > when > > ApplicationContext( context == "*" ) > > ad : ApplicationData( age == "" || ( == null )) > > then > > ad.setReturnMsg( "\n age should not be null or empty" ); > > end > > > > rule "Rule2" > > dialect "mvel" > > when > > ApplicationContext( context == "screen1.panel1.ed" ) > > ad : ApplicationData( $age : age != null , age != "" , age < 0 || > > > 100, minIssrdAge == "Years" ) > > then > > ad.setReturnMsg( "\nage is out of the range(i.e. < 0 and > 100)" > ); > > end > > > > rule "Rule3" > > dialect "mvel" > > when > > ad : ApplicationData( $age : age != null , age != "" , age <0 || > > > 600, minIssrdAge == "Years" ) > > then > > ad.setReturnMsg( "\nage is out of the range(i.e. < 0 and > 600)" > ); > > end > > > > On 13 April 2011 17:19, Benson Fung <benson.red...@gmail.com> wrote: > >> > >> Hi, > >> > >> Here is the scenario : > >> > >> If there are 2 edit boxes and 2 dropdown list at the frontend like. > >> > >> > >> dropdown(minIssrdAge1) editbox(age1) > >> dropdown(minIssrdAge2) editbox(age2) > >> > >> everytime when I lost focus the editbox(age1 or age2), the > >> editbox(age1 or age2) value will be validated against the following > >> rules. > >> i.e. minIssrdAge1 and age1 will be validated together if lost focus > >> the editbox age1. > >> minIssrdAge2 and age2 will be validated together if lost focus > >> the editbox age2 > >> > >> Rule1 is mandatory because both editbox are required field. > >> However, editbox(age1) is only valid within the 0 and 100. and > >> editbox(age2) is only valid within 0 and 600. > >> > >> In other words, editbox(age1) have to be validated against Rule1 + > >> Rule2. However, editbox(age2) have to validated against Rule1 + > >> Rule3. > >> > >> My question, how to design the rule attribute or at the java program > >> side so that different editbox can be validated against different > >> rule. > >> > >> Please help. I can't find any solution by now. > >> > >> rule "Rule1" > >> salience 1 > >> dialect "mvel" > >> when > >> ad : ApplicationData( age == "" || ( == null )) > >> then > >> ad.setReturnMsg( "\n age should not be null or empty" ); > >> end > >> > >> > >> rule "Rule2" > >> dialect "mvel" > >> when > >> ad : ApplicationData( $age : age != null , age != "" , > >> minIssrdAge > >> == "Years" ) > >> eval(Integer.parseInt($age) < 0) or > >> eval(Integer.parseInt($age) > 100) > >> then > >> ad.setReturnMsg( "\nage is out of the range(i.e. < 0 and > > > >> 100)" ); > >> end > >> > >> rule "Rule3" > >> dialect "mvel" > >> when > >> ad : ApplicationData( $age : age != null , age != "" , > >> minIssrdAge > >> == "Years" ) > >> eval(Integer.parseInt($age) < 0) or > >> eval(Integer.parseInt($age) > 600) > >> then > >> ad.setReturnMsg( "\nage is out of the range(i.e. < 0 and > > > >> 600)" ); > >> end > >> _______________________________________________ > >> rules-users mailing list > >> rules-users@lists.jboss.org > >> https://lists.jboss.org/mailman/listinfo/rules-users > > > > > > _______________________________________________ > > rules-users mailing list > > rules-users@lists.jboss.org > > https://lists.jboss.org/mailman/listinfo/rules-users > > > > > > _______________________________________________ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users >
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users