您的位置:首页 > 其它

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

2013-10-14 12:46 567 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: