public class Controller extends PageFlowController
{
/**
* @common:control
*/
private com.bea.p13n.controls.login.UserLoginControl userLoginControl;
/**
* @common:control
*/
private com.bea.p13n.controls.profile.UserProfileControl userProfileControl;
/**
* @common:control
* @jc:rules-executor filterClassName="com.bea.p13n.user.Classification" filterResults="true"
rulesetUri="/rulesets/getFromProfile2.rls"
*/
private com.bea.p13n.controls.rules.RulesExecutorControl rulesExecutorControl;
/**
* @jpf:action
* @jpf:forward name="default" path="default.jsp"
* @jpf:forward name="goldCard" path="goldCard.jsp"
* @jpf:forward name="silverCard" path="silverCard.jsp"
* @jpf:catch type="com.bea.p13n.controls.exceptions.P13nControlException" path="error.jsp"
* @jpf:forward name="error" path="error.jsp"
*/
protected Forward evaulateRuleSetAction(EvaluateRuleSetActionForm form)
throws P13nControlException
{
// Start with an empty list into which we add objects to populate
// the working memory of the rules engine
List wmObjects = new ArrayList();
ProfileWrapper pw = userProfileControl.getProfileFromRequest(this.getRequest());
if ( pw == null)
{
throw new P13nControlException("Undable to retrieve profile from request. " +
"Make sure PortalServletFilter is configured in web.xml for an anonymous user, " +
"or that a user has logged in.");
}
// This one will be the condition that fires the rule
Integer value = new Integer(6);
userProfileControl.setProperty(pw, "FooPropertySet", "CreditScore", value);
wmObjects.add(pw);
// Evaulate all rules in the ruleset. Parameters have been declared on the control via
// the rulesExecutorControl property editor.
Iterator iter = rulesExecutorControl.evaluateRuleSet(wmObjects.toArray());
List results = new ArrayList();
// Let's say we're lookig for GoldCardMembers
Classification goldCardMembers = new Classification("GoldCardMembers");
Classification silverCardMembers = new Classification("SilverCardMembers");
// And we'll direct them to a certain page depending on how the rule evaluates
Classification classification = (Classification)iter.next();
// Now you would do something with that. Like maybe show them a different page
if (classification.equals(goldCardMembers))
{
// Direct them to high-price stuff
return new Forward("goldCard");
}
else if (classification.equals(silverCardMembers))
{
// Direct them to lower-price stuff
return new Forward("silverCard");
}
// Otherwise, it defaults. Something went wrong...check the rule conditions or turn
// off filtering on the control to see what's in working memory
}
}
return new Forward("default");
}
|