Hi Drew,

What you ask for shouldn't be too difficult to implement. If I had to do
it, I'd use reflection, as you mentioned, and I'd just add a new field
in configuration file to allow the user to specify the name of the
method to be called. However, if you want the methods to be executed
using one instance, then you should also add something to identify the
instance you want to use for every operation. If you wanted to call
methods that have parameters things could get much more cumbersome.

On the other hand... do you think it is really necessary to call
different methods in the same class?. If you store the bean in the
session( or in servlet context) and each operations is a small class
that gets the parameters and calls the appropriate method from that
shared bean, things get easier and, IMHO, more cleanly separated.
As you pointed out, this Bean that you keep between calls inside the
same user session, fits pretty much into the definition of a session
EJB.

As I conclusion, I'll just say that I opted for the command pattern
because it keeps the controller servlet, and the configuration file,
simpler and because I prefer to have a set of simple classes that
perform each one a simple operation than one, or more classes, that
implement everything. I find this arrangement easier to understand,
debug, and easier to work with, when you develop in group. But that's a
matter of taste.

Just my 2c,
Dan
-------------------------------------------
Daniel Lopez Janariz ([EMAIL PROTECTED])
Web Services
Computer Center
Balearic Islands University
-------------------------------------------

Drew Cox wrote:
>
> I have been following with interest over the last few months the various
> threads on web app architecture.  I am currently working on a small
> servlet/JSP system and using a version of the single controlling servlet
> model that has been discussed quite a bit.  I have an implementation
> question.
>
> I like the idea proposed by some people that the configuration of the web
> actions be stored in a HashTable, which is loaded on application a startup
> from a properties file or a database.  This allows the developer to avoid
> hard-coding the following relationships:
>
> 1) The web "action" requested in the HTTP request, eg. URI
> /controller/getClient
> 2) The class that the controlling servlet uses to processes the web action,
> eg.  Barrack.JspBeans.ClientGetter.
> 3) The JSP page the bean or servlet then forwards to, to display the
> required output, eg. URI /display/showClient.jsp
>
> It seems common to implement the Command pattern in the processing class (#2
> above), so the controlling servlet can simply call a "doAction(request,
> response)" method on the class, without knowing anything about it.  All
> makes sense so far...
>
> So, finally, on to my question.
>
> What if you would prefer to be able to configure both the class and a
> specific method name that each web action maps to?  Is there and easy way
> call a dynamically named method on a dynamically named class?  I guess this
> is more of a generic Java question now, sorry.  I suspect that there are
> things in the Reflection API that allow this, this is where I am heading
> next.
>
> The reason for this is that otherwise I have to create a separate class for
> each action.  I would really prefer to group some of these action processing
> methods together into a single class.  This is both to keep things tidy (?)
> and to to store some state information in that bean from one method call to
> the next (the class would be stored in the session).
>
> This is for things like implementing a multi-page workflow where the bean
> could then check it's internal state to ensure the pages are being completed
> in the correct order, or what the previous page should be if the user want
> to go "back".  It also seems a little closer to my limited understanding of
> EJB Session Beans, which I believe implement the various actions that can be
> performed as separate methods (??).
>
> I'm interested in any opinions people have on (a) how to implement this and
> (b) if they don't think it's a good idea, why.
>
> Regards
>
> Drew Cox
> Barrack Consulting

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to