添加名为 ejb/stockfacade 的引用。

在 details 部分单击 browse 按钮。

选择 stockfacade ejb 并单击 ok。

会话 bean 和绑定信息都必须填写完整。

web 应用程序会使用 ejb 本地接口来访问数据。ejb 本地接口将符号作为输入并返回一个 accessstockquotevo。这是一个带有 getters 和 setters 的简单 javabean。
public interface stockfacadelocal extends javax.ejb.ejblocalobject {
public accessstockquotevo getcurrentstockdata(string symbol)
throws symbolnotfoundexception,
stockexception,
invalidsymbolexception;
...
}
ejb jar 提供了一个简单的 delegate 对象,它隐藏了对象的复杂性。该委托是一个单独的 java 对象,它提供了一个类似的接口。
public class accessquotedelegate
{
private stockfacadelocal stockfacade;
public static accessquotedelegate accessquotedelegate = null;
public static accessquotedelegate getaccessquotedelegate() throws stockexception
{
if(accessquotedelegate == null)
{
accessquotedelegate = new accessquotedelegate();
}
return accessquotedelegate;
}
private accessquotedelegate() throws stockexception
{
initialcontext context;
try
{
context = new initialcontext();
stockfacadelocalhome home = (stockfacadelocalhome)context.lookup("java:comp/env/ejb/stockfacade");
stockfacade = home.create();
}
catch (namingexception e)
{
throw new stockexception(e.getlocalizedmessage());
}
catch (createexception e)
{
throw new stockexception(e.getlocalizedmessage());
}
}
public accessstockquotevo getcurrentstockdata(string symbol)
throws symbolnotfoundexception, stockexception, invalidsymbolexception
{
return stockfacade.getcurrentstockdata(symbol);
}
}
创建 viewstockdata.jsp
设置好 ejb 对象之后,我们就可以创建 stock data 页面,用它来显示调用 stockfacade stockdata 方法的结果。
首先,我们创建一个新的 jsf 页面来显示提交 stock data request 的结果。
在 application developer 中,右键单击 personaltradejsf 页面中的 webcontent 文件夹,选择 new => faces jsp file。

在 file name 字段中键入 viewstockdata.jsp,然后选择 create from page template。

确保选中 stockpagetemplate.jtpl。单击 finish。

现在我们使用 visual palette 来添加标签。
在 faces visual palette 中选择 output 组件。

将 output 组件添加到页面中。将文本大小设为 18,文本值设为:view stock data。

ejb 返回一个正规的 java bean。我们将作为页面数据添加该 java bean。
转到 page data 视图。右键单击 jsp scripting 并选择 new => javabean。

闽公网安备 35060202000074号