您的位置:首页 >> 编程开发 >> Java >> Java基础 >> Eclipse >> 正文
Eclipse RSS
 

Tutorial for building J2EE Applications using JBOSS and ECLIPSE -4

http://www.rdxx.com 04年08月30日 12:12 Blog 我要投稿

标签: Tutorial , JBoss , J2EE , Eclipse , ATI , UI , ONS , IP , JB
 

Chapter 4.

Creating a Stateful Session Bean

This chapter covers how to create a stateful session EJB component. Unlike stateless beans, stateful bean instances are associated with a particular client session and can therefore maintain information useful during the lifetime of that session. A classic and familiar example of this in a web e-commerce context is that of a shopping cart.

We'll try something a little less ambitious for the time being! This bean is similar to the StoreAccess Bean created in the previous chapter except that it will store the userID of the client, after authentication is successful.




Note : This bean will not be used further in tutorial, as this chapter demonstrates how stateful beans are created.

Tasks :

  1. Create a Stateful Session Bean named StoreAccessState.

  2. Add a business method in the bean named loginUser with the signature

    public String loginUser (String username, String password)

  3. Add a call back method ejbCreate with the signature

    public void ejbCreate (String userID)

  4. Generate the DAO interface.

  5. Access the DAO named StoreAccesDAOImpl under package au.com.tusc.dao, created and implemented in the previous chapter. This DAO has a method named loginUser, called by loginUser in the bean with the signature

    public String loginUser (String username, String password)

  6. Deploy the StoreAccessState bean.

  7. Create your test client named SessionStateClient under package au.com.tusc.client.

  8. Run your client and test the bean.



Create Stateless Bean :


Go To Package Explorer > Expand Mystore (project) node > select src, right click and a menu will pop up.

On pop up menu > New > Lomboz EJB Creation Wizard.

Enter the package name au.com.tusc.sessionState, bean name StoreAccessState and select bean type as stateful > Finish.

This will create package named au.com.tusc.sessionState under src and StoreAccessStateBean under that package as shown below.


As we can see from the figure above it has created a class level tag @ejb.bean, which has assigned the bean type, name and its JNDI name which will be generated in the Home interface. This tag will also generate deployment descriptors in ejb-jar.xml and jboss.xml file as well once you generate your EJB classes, which is covered later on in this chapter.

Note: It will generate the bean name, jndi-name and type of bean in file. Also, the name of file is appended with word 'Bean' as you gave the name of the bean as StoreAccess only. So be careful with your naming convention, as you only need specify the bean name in the wizard (ie. without a 'Bean' suffix as the wizard will append that for you).




Create DAO Interface :


Since we are going to use a DAO to access the database for this Stateful Bean, we will use the StoreAccesDAOImpl class which was created and implemented in the previous chapter. This will provide the implementation for the generated DAO interface.

Now go to your Bean class and declare this tag at class level (i:e; at top), as described below to generate the DAO interface.

   

9 7 3 1 2 3 4 5 6 4 8 :


 
 
打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站