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值为得到的列表中的值。真是莫名其妙,我已经三天都难以释怀了,网上也查了不少,始终没有找到答案,请各位指教,不胜感激。