Hi,
>I was just wondering ...
>Your are using a single instance of action class to process all
>the requests.
>Also to keep it thread safe, you don't use any instance variables.
>In that case
>why do we even need a single instance ? Why can't we just invoke
>the "static"
>method from the class. Something like Integer.ParseInt () ?
>
>Is it a bad practice to use classes this way ? or it has something
>to do with
>the fact that static methods are not overridden ?
I too have often wondered this. Craig/Daniel..whats the deal with this? Is
there a reason if each action class is to be one instance, not to make it a
static class? I mean..I don't believe I'll be extending any action class.
Also, I have a question about multi-page forms. Each form would call a
"different" action class, right? This means, if I have 10 pages of forms,
and the last one "finalizes" the process (saves data, etc), I have a few
things I have to worry about:
- Do I use one action class for all the pages, and if so, do I pass in some
parameter such as the hidden field command type of parameter, to signify
which method in the action to take? Or is it better to use a single action
class (my preference) for each form. In my mind, having a single action
class for each form allows you to more easily debug and manage the form(s)
and pages.
- To add to this, if I did use multiple action classes, would I use a
JavaBean stored in the session, and each action class gets it out, gets/sets
stuff, then puts it back in until the last one, which handles the
transaction, then removes the bean from the session?
- If using EJB, does the action class just act as an adaptor (I believe you
said this Craig), it creates the EJBHome and EJBRemote connections, calls
the ejb methods to do the logic?
- Again to add to the above, if so, is it best to pass the JavaBean to the
EJB (serialized ofcourse) and then put that same JavaBean (which came back
from the EJB with possible changes) in the request or session so the JSP
page forwarded to can use it? On that note, a simple bit of code that I am
not certain would be correct, but I'll give it my best shot to demonstrate
what I am talking about.
---
action class
----
{
MyBean bean = null;
if( request.getSession(true).getAttribute("MyBean") != null )
bean = (MyBean) request.getSession(true).getAttribute("MyBean");
else
bean = new MyBean();
EJBHome home = (some code to get EJB home)
EJBRemote ejb = home.create();
bean = ejb.doLogic(bean);
request.getSession(true).setAttribute("MyBean", bean);
... forward to JSP page ...
}
Forgive me if this is bad code..I really only saw my first demonstration of
using EJB at the Sun/Sybase Whistlestop seminar yesterday, so I am going on
memory. At any rate, I am wondering if I can use the same JavaBean that will
be displayed on the JSP page as a parameter to the EJB, and that the EJB can
return that same bean back with the modifications the logic has performed.
If not, what would be a way to do this? Incidentally, I dont want you to
give me all the answers..I can learn this on my own. My main reason for
asking is to get an idea of how I will need to architect the action classes,
ejb, javabean and jsp so that they all work together in harmony for each
incoming request. I was told that using a stateless EJB would be "faster"
performance wise and thus this leads me to believe that the JavaBean on the
web server side should be kept in the HttpSession to maintain state, while
the EJB is used for scalability, logic, security and pooling abilities. The
reason the spokesperson said this was that by making it stateless it would
cut down on network traffic use (not exactly sure how stateful and stateless
effects traffic over the network..but..). If this is true, then it seems
that the best thing is to avoid stateful EJB, to speed up performance. If
this is the case, does it make it "faster" by keeping it in the HttpSession
and only passing the bean to EJB (and back) so that the EJB can be given the
parameters from the form?
I did forget to ask the guy that yesterday, but there was a room full of 400
people with questions..so I was glad to get what I did in.
By the way..if anyone wants to know, the seminar wasn't bad, but it mostly
ties in to the Sybase app server, which to my surprise is an award winning
app server and 3rd in the choice of app servers, and I do like how PowerJ
makes it super easy to create a full EJB where you only have to put in your
business logic, and deploy it. What concerns me is the amount of work
involved in deploying EJB. It seems for each EJB you need, every time you
make a change to it, you have to deploy it again to the server. Is there any
chance you can work on EJB without first jarring it up and deploying it?
Does it always require a descriptor, deployment, etc to work. That is very
time consuming constantly compiling it, deploying it, testing it, then going
back to the code again.
Anyways..if you live close, it was a nice seminar. I only stayed for the
first half. They do serve a nice breakfast and very nice lunch! And its
free! So if your close, take the day off if you can and go check it out.
Thanks for the help everyone.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets