struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "emmanuel.boudrant" <b...@yahoo.fr>
Subject Struts event programming ! ... re sorry
Date Mon, 01 Oct 2001 14:06:40 GMT
What do you about event programming in Java ServerSide programming ?With this html button :<input
type="submit" name="ok" value="ajouter">	invoke method onAjouter(,,,)<input type="submit"
name="ok"value="enregistrer">	invoke methodonEnregistrer(,,,) Etc... package  com.csi.controller;//
Strutsimport  org.apache.struts.action.*;// Servletimport  javax.servlet.http.HttpServletRequest;import
 javax.servlet.http.HttpServletResponse;// Import log4j classes.import  org.apache.log4j.Category;import
 org.apache.log4j.BasicConfigurator;// Reflectimport  java.lang.reflect.Method;/** * Titre
: MyAction.java * Description : Event Programming in Struts ;) * Copyright :    Copyright
(c) 2001 * @author : b7st@yahoo.fr * @version 0.00001a */public abstract class MyAction extends
Action {    static Category log =Category.getInstance(MeeschaertAction.class);    public MyAction
() {    }    public ActionForward perform (ActionMappingmapping, ActionForm form, HttpServletRequest
request,            HttpServletResponse response) throwsjava.io.IOException, javax.servlet.ServletException
{                    // Get submit parameter 'ok' value        // ex: <input type="submit"
name="ok"value="ajouter">        String button = request.getParameter("ok");        if
(button != null) {            // If ok, get the good method name             // ex: onAjouter
           String methodName = "on" +button.toUpperCase().substring(0, 1)                
   +button.toLowerCase().substring(1, button.length());            Method method = null; 
          Class thisAction = this.getClass();            Class param[] = new Class[4];   
        param[0] = ActionMapping.class;            param[1] = ActionForm.class;          
 param[2] = HttpServletRequest.class;            param[3] = HttpServletResponse.class;   
        try {                // Test if the method exist inderived class                method
=thisAction.getDeclaredMethod(methodName, param);                Object value[] = new Object[4];
               value[0] = mapping;                value[1] = form;                value[2]
= request;                value[3] = response;                // Yes, so invoke it !     
          return (ActionForward)method.invoke(this, value);            } catch (NoSuchMethodException
e) {                log.debug("EVT(" + e + "): No " +methodName + "(,,,) found, using go(,,,)");
           } catch (Exception e) {                log.warn("EVT(" + e + "): No " +methodName
+ "(,,,) found, using go(,,,)",                        e);            }        }        //
Else invoke normal method        return  go(mapping, form, request, response);    }    public
abstract ActionForward go (ActionMappingmapping, ActionForm form,            HttpServletRequest
request,HttpServletResponse response) throwsjava.io.IOException,            javax.servlet.ServletException;}
Emmanuel,


---------------------------------
Do You Yahoo!?
Yahoo! Courrier Un e-mail gratuit @yahoo.frĀ !

Mime
View raw message