AppComposer uses JavaBeans that construct a visual interface to access EJBs for you, so if you are used to writing code to use EJBs, you will notice that this feels a little different.› EJB components that you add to a capsule have the Home and Remote interface methods accessible from the single EJB icon in the outline view.› When using a find method on an entity bean that returns more than one remote interface, AppComposer provides methods to iterate over the references returned.
Now you are ready to add the SimpleBank EJB.› By default, properties of the bean use JBoss as the EJB server. DigiSliceEJBHome is the name used in JNDI to look up the bean. If you use an EJB container other than the built-in JBoss, and your EJB application server uses a value other than what is in ejb-name in ejb-jar.xml, you have to change the value.
Html -> HTMLText
HTMLTextactor to BalanceText.
SimpleBankbean in the outline SimpleBankBean.
At this point, the bean is accessible. That is, the servlet capsule can find and utilize the deployed bean.› You now need an action group behavior to handle the access.› For this tutorial, you will provide handling for two possible scenarios:
For this example, assume that the only possible error the user can make is to enter an invalid account number. Any error the servlet encounters will generate the error message that the account was invalid.
To decide whether to display the error message or the account balance, the SimpleBankBean looks in the database for an entry whose account number matches the parameter from the form.› If no matching entry is found, it throws an exception.› Since the account number is the primary key of the database, only one account exists for any valid account number.
You need to create behaviors that look up the account, warn of any errors, and display the balance amount from a successful search. The stimulus is when the actor BalanceText is about to be output.
If FindAccount throws an exception, this example assumes that a matching account was not found. To handle this case, add a behavior that activates when FindAccount throws an exception. For simplicity, assume that all exceptions are caused by an invalid account number. In a real application, you would probably want to distinguish between an invalid account number and other kinds of errors.
Now that you have provided handling for potential errors, you can proceed with handling valid entries.
When the EJB SimpleBankBean finds a database entry for the account number that the user supplied, it generates an EJB.selected event. When this happens, the only thing left to do is to ask SimpleBankBean for the balance of the account and output it.›
To access the data, you can define a call to a remote reference of a SimpleBankBean that currently represents that data we are interested in. To do this, create a behavior that activates on EJB.selected from the SimpleBank EJB, retrieves the account balance from the EJB, converts it to a string and assigns it to the BalanceText actor.
Note that the account balance is returned as a numeric (Double) value, but Java automatically converts it to a string when we concatenate it onto the end of another string.
You are now done building the capsule!› Save your work.
Your outline should look like the following:
If the configuration has been set up correctly and the capsule has no errors, you should see the following page:
Some valid account numbers are : 111111, 123456, 000001, and 987654.› Enter one of these and click Get Balance.› You should see something similar to the following page:
If you enter an invalid account number, you should see an error message.› If anything is wrong with how you set up the example you will see the error message. If you have entered a valid account number and are getting the invalid account message, check that:
You have now completed this tutorial! To see a more complex AppComposer project that uses EJBs, see the icDVD example from the AppComposer/examples directory.