WCS学习笔记(第四天) - 使用data bean从MyNewControllerCmd 向 MyNewView传递信息

本文介绍如何在WebSphere Commerce中通过创建新的数据Bean和控制器实现数据交互。包括编写Controller接口及其实现,修改JSP页面以显示数据Bean中的信息,并提供了测试步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 编写Controller接口和实现:
  a.WebSphereCommerceServerExtensionsLogic >src >com.ibm.commerce.sample.databeans 新建MyNewDataBean.java (可从IBM教程获取),方法体主要对callingCommandName和calledByControllerCmd的set、get方法

 /// Section 1 /////////////////////////////////////////////
/// create fields and accessors (setter/getter methods) 

  private java.lang.String callingCommandName = null;
  private boolean calledByControllerCmd = false;
  
  
  public java.lang.String getCallingCommandName() {
    return callingCommandName;
  }
  
  public void setCallingCommandName(java.lang.String newCallingCommandName) 
  {
    callingCommandName = newCallingCommandName;
  }
  
  public boolean getCalledByControllerCmd() {
    return calledByControllerCmd;
  }
  
  public void setCalledByControllerCmd(boolean newCalledByControllerCmd) 
  {
    calledByControllerCmd = newCalledByControllerCmd;
  }
  
/// End of Section 1 ////////////////////////////////////

 

  b. 修改WebSphereCommerceServerExtensionsLogic> src > com.ibm.commerce.sample.commands.MyNewControllerCmdImpl.java控制实现:

      导入data bean

/// Import Section 1 ///////////////////////////////
import com.ibm.commerce.sample.databeans.MyNewDataBean;
/// End of Import Section 1 ////////////////////////

    修改performExecute方法,分别对bean中callingCommandName和calledByControllerCmd赋值,并rspProp.put于mndbInstance,代码实现如下:

/// Section 3A/////////////////////////////////////////

  /// instantiate the MyNewDataBean databean and set the properties, 
  ///  then add the instance to resProp for response
  
  MyNewDataBean mndb = new MyNewDataBean();
  mndb.setCallingCommandName(this.getClass().getName());
  mndb.setCalledByControllerCmd(true);

/// end of section 3A/////////////////////////////////////////

/// Section 3B/////////////////////////////////////////
  rspProp.put("mndbInstance", mndb);

/// end of section 3B/////////////////////////////////////////

 

2. 修改JSP页面:

  a. 在MyNewJSPTemplate.jsp的SECTION 5中增加下面代码,用于判断和显示bean传递的信息

<!-- SECTION 5 -->

<c:if test="${mndbInstance.calledByControllerCmd}">
   <fmt:message key="Example" bundle="${tutorial}" /> <br />
   <fmt:message key="CalledByControllerCmd" bundle="${tutorial}" /> 
      <br />
   <fmt:message key="CalledByWhichControllerCmd" bundle="${tutorial}" /> 
   <b><c:out value="${mndbInstance.callingCommandName}" /></b> <br /> 
      <br />
</c:if>

<!-- END OF SECTION 5 -->



3. 测试:

  a. 启动server

  b. 访问: http://localhost/webapp/wcs/stores/servlet/MyNewControllerCmd (注:由于缓存可在url后加如: ?StoreId=10051 )

  c. 访问: http://localhost/webapp/wcs/stores/servlet/MyNewView (注:由于缓存可在url后加如: ?StoreId=10051 )

 

参考: http://pic.dhe.ibm.com/infocenter/wchelp/v7r0m0/topic/com.ibm.commerce.developer.tutorial.doc/tutorial/ttd14a.htm 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值