What, exactly, do you mean by "when the rule violates"?
-W

On 14/06/2012, Brajesh <[email protected]> wrote:
> Hi Friends
>
> I am trying to create a web page with a form, so when we click on submit,
> we
> are redirected to the result web page, but the content of this page will be
> generated according to the rules i created in my drl file. Does anyone
> knows
> the easiest way to do this? are they a way to call the drl file from the
> jsp
> file, or the java file?
>
> My Jsp file
> <form:form method="post" action="login.htm" commandName="loginForm"
> id="loginForm">
>               <table>
>               <tr>
>                   <td>Enter username:</td>
>                   <td><form:input path="UserName" style="width:250px"
> maxlength="75"/></td>
>               </tr>
>               <tr>
>                   <td>Enter password</td>
>                   <td><form:password path="UserPassword" style="width:250px"
> maxlength="75"/></td>
>               </tr>
>        </table>
>          <table width="100%" border="0" cellspacing="0" cellpadding="0">
>               <tr>
>                               <td valign="top" >
>                                       <label>
>                                           <input type="submit" value="Save" />
>                                       </label>
>                                       <label>
>                                          <input type="reset" value="clear"/>
>                                       </label>
>                         </td> 
>                 </tr>
>       </table>                                                        
>    </form:form>
>
> My controller class
>
> @RequestMapping(value="login.htm", method=RequestMethod.POST)
>       public String showAffilaiteform(Map<String, Object> model,login
> loginform,BindingResult result) {
>               String target = AFFILIATE_REGISTRATION;
>               try{
>                       testDAO.drools(loginform);
>                       model.put("affiliateRegistrationForm", new 
> AffiliateUserRegistration());
>               
>                  }catch(Exception e)
>               {
>                       e.printStackTrace();
>               }
>               
>
>               return target;
>       }
> My TestDao class
>
> public class TestDAO implements ITestDao {
>       
>
>
>        public void drools(login loginform) {
>
>                 try {
>                        // load up the knowledge base
>                        KnowledgeBase kbase = readKnowledgeBase();
>                        StatefulKnowledgeSession ksession =
> kbase.newStatefulKnowledgeSession();
>                        KnowledgeRuntimeLogger logger =
> KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "myLog");
>                        ksession.insert(loginform);
>                        ksession.fireAllRules();
>                        logger.close();
>                    } catch (Throwable t) {
>                        t.printStackTrace();
>                    }
>
>
>       }
>       
>         private static KnowledgeBase readKnowledgeBase() throws Exception {
>               KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>       
> kbuilder.add(ResourceFactory.newClassPathResource("LoginRules.drl"),
> ResourceType.DRL);
>               KnowledgeBuilderErrors errors = kbuilder.getErrors();
>               if (errors.size() > 0) {
>                   for (KnowledgeBuilderError error: errors) {
>                       System.err.println(error);
>                   }
>                   throw new IllegalArgumentException("Could not parse
> knowledge.");
>               }
>               KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
>               kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
>               return kbase;
>           }
>  My DRL file
> import com.ri.bean.login;
>
>       rule "b"
>     dialect "mvel"
>           when
>               login( userName == "" ||==null)
>           then
>           System.out.println("hello");
>               login lo = new login();
>       
> end
> These are my files and my application runs without any error.Now I want to
> show a message on my jsp page when the rule violates.can anybody provide me
> a small piece of code.
>
> Regards
> Brajesh
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/jsp-java-and-drl-file-tp4017955.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to