Tapestry莫名其妙的问题,求大虾指教。

YYZhQ 2006-10-10 09:55:25
我先把代码摘抄如下:
NodeTest.java

package com.test.tools;

import java.io.File;
import java.io.Serializable;

public class NodeTest implements Serializable{

/**
*
*/
private static final long serialVersionUID = 4737690332317229958L;

private String _sTestString;

public NodeTest(String name) {
_sTestString = name;
// TODO Auto-generated constructor stub
//this.name = name;
}


public static void main(String[] args){
NodeTest n = new NodeTest("test");
System.out.println(n.getSTestString());
}


public String getSTestString() {
return _sTestString;
}


public void setSTestString(String testString) {
_sTestString = testString;
}


}


TableListTest.java

package com.test.tapestry.compentent;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.InjectComponent;
import org.apache.tapestry.contrib.table.components.TableView;
import org.apache.tapestry.html.BasePage;

import com.test.tapestry.global.GetTableList;
import com.test.tapestry.global.TableNode;
import com.test.tools.NodeTest;

public abstract class TableListTest extends BasePage {


@InjectComponent("table")
public abstract TableView getTable();

@SuppressWarnings("unchecked")
public List getListValues() {
ArrayList _list = GetTableList.getTable("ResourceDir",null);
Iterator e = _list.iterator();
List _NodeTestLists=new ArrayList();
while(e.hasNext()){
NodeTest t = (NodeTest)e.next();
System.out.println("得到文件"+t.getSTestString());
_NodeTestLists.add(new NodeTest(t.getSTestString()));
}
System.out.println(_NodeTestLists);
return _NodeTestLists;
}


public boolean getCheckboxSelected() {
return getSelectedNodes().contains(getCurrentNode());
}

@SuppressWarnings("unchecked")
public void setCheckboxSelected(boolean bSelected) {
NodeTest currNodeTest = getCurrentNode();
Set setSelectedNodeTests = getSelectedNodes();
System.out.println("执行选择添加");
System.out.println(setSelectedNodeTests);
if (bSelected)
setSelectedNodeTests.add(currNodeTest);
else
setSelectedNodeTests.remove(currNodeTest);
System.out.println("选择的文件"+setSelectedNodeTests);
setSelectedNodes(setSelectedNodeTests);
}


@SuppressWarnings({"unchecked","unchecked"})
public void delNodes(IRequestCycle objCycle) {

}

public abstract NodeTest getCurrentNode();

public abstract Set getSelectedNodes();

public abstract void setSelectedNodes(Set set);

}

TableList.html

<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
<body bgcolor="transparent" jwcid="@Body">
<script language="javascript">
function submitDel(){
if(confirm("确定删除?")){
document.form.submit();
return true;
}else{
return false;
}
}
</script>
<form jwcid="form1">
<span jwcid="checkboxGroup">
<TABLE jwcid="table" align="center" border="1" bgcolor="#c0c0c0" width="500px">
<tr>
<td>
<span jwcid="controlCheckbox" />
</td>
<td jwcid="tableColumns" />
</TR>


<tr jwcid="tableFormRows">
<td>
<span jwcid="checkbox" />
</td>
<td jwcid="tableValues" align="center" />
</tr>
<tr>
<td colspan="6">
<span jwcid="tablePages@Contrib:TableFormPages" />
</td>
</tr>

</TABLE> </span> <span jwcid="delButton" value="删除" />
</form>
</body>
</html>


TableList.page
<?xml version="1.0"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<page-specification class="com.test.tapestry.compentent.TableListTest">
<property name="selectedNodes"
persist="session"
initial-value="new java.util.HashSet()"/>
<component id="form1" type="Form">
<!--binding name="listener" value="listeners.formSubmit"/-->
</component>
<component id="checkboxGroup" type="Contrib:CheckboxGroup"/>
<component id="controlCheckbox" type="Contrib:ControlCheckbox"/>
<component id="checkbox" type="Contrib:ControlledCheckbox">
<binding name="value" value="checkboxSelected"/>
</component>
<component id="table" type="Contrib:TableView">
<binding name="source" value="listValues"/>
<binding name="columns"
value="literal:sTestString"/>
</component>
<component id="tableColumns" type="Contrib:TableColumns"/>
<component id="tableFormRows" type="Contrib:TableRows">
<binding name="row" value="currentNode"/>
<binding name="keyExpression" value="literal:toString()"/>
</component>
<component id="tableValues" type="Contrib:TableValues"/>
<component id="delButton" type="Submit">
<binding name="listener" value="listener:delNodes"/>
</component>

</page-specification>


问题是TableListTest的setCheckboxSelected函数中,执行断点debug时,如果NodeTest如上面所列,则执行NodeTest currNodeTest = getCurrentNode();时currNodeTest值为null,而同样的代码,不做任何改动,仅将NodeTest继承于File,则currNodeTest值为得到的列表中的值。真是莫名其妙,我已经三天都难以释怀了,网上也查了不少,始终没有找到答案,请各位指教,不胜感激。
...全文
319 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
YYZhQ 2007-01-19
  • 打赏
  • 举报
回复
呵呵,不好意思,一段时间没来,结贴了。
sqz007 2006-10-20
  • 打赏
  • 举报
回复
呵呵,现在用tapestry的人太少了
YYZhQ 2006-10-11
  • 打赏
  • 举报
回复
找到原因了,跟继承不继承File无关,只要重写NodeTest的toString方法就行了,如果不重写,它会使用Object基类的toString方法,返回类似于com.test.tapestry.global.TableNode@c1b531之类的字串,我想大概跟这个有关吧,File重写了toString方法,所以继承于File就继承了其toString方法,就不会出错。在网站上也搜到一些相关的东西,其中有这样一段话,虽不是很明白,但觉得似乎跟这个有关,先放在这里,供大家参考。
It appears that the reason is that the interceptor tries to add all request parameters to the ognl stack. Some of these parameters are "reserved" for the webwork portlet framework, such as webwork.portlet.mode, webwork.portlet.eventAction and so on. When adding these keys to the stack, it splits the dotted notation into a "path" to a property, which of course does not exist.

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧