Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

stateless bean and parameters

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a stateless session bean and I wish to pass some parameters to the bean instances. I cannot do it through create()/ejbcreate(), since they wont accept parameters. How do I do it then? Through business methods?

Regards,
PK
 
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of *parameter* do you need ? could you explain further ??
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let us just consider a "Hello World" program for its simplicity. Say there is a jsp page that accepts the first name and last name. This then gets passed on to a servlet which calls the create() method on a stateless session bean. Then it calls the business method hello() on the session bean which returns "Hello World, first_name last_name". Now, how do I pass the first name and the last name? A real convenient way to do this would have been to pass the names through the create method. But this is not permitted. So, passing it through the business method(hello(), in this case) is one option.

Is there any better option?

PK
 
author & internet detective
Posts: 41263
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prakash,
You should definitely pass the parameters to the business method because they are used in the business method.

Since this is a stateless bean, it shouldn't have instance variables as those could change between, or even during, invocations.
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Since this is a stateless bean, it shouldn't have instance variables as those could change between, or even during, invocations.



What is the solution then?

Regards,
PK
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prakash hello

It might help to say that a SLSB method is similar to a Java static method in that you just provide an input and get an output, but don't ever store class attributes. (The analogy ends here though, as SLSBs have less overhead whereas static methods are not very efficient). It is suitable for simple input-output processing where data doesn't need to be saved, whereas a SFSB method is used where the data might be needed by other methods or classes later, after the method you are calling has returned.

Hope this helps.

Alastair
 
Onion rings are vegetable donuts. Taste this tiny ad:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic