[Tapestry5] Tapestry 5 使用AjaxFormLoop 添加行时(onAddRow)报错,麻烦进来看下

foollb 2011-01-12
控制台输出错误信息:
ERROR 14:41:16 {admin}Processing of request failed with uncaught exception: The rendered content did not include any elements that allow for the positioning of the hidden form field's element.
java.lang.IllegalStateException: The rendered content did not include any elements that allow for the positioning of the hidden form field's element.
at org.apache.tapestry5.corelib.internal.HiddenFieldPositioner.getElement(HiddenFieldPositioner.java:74)
at org.apache.tapestry5.corelib.components.FormInjector$1.renderMarkup(FormInjector.java:236)
at org.apache.tapestry5.internal.services.PageRenderQueueImpl$Bridge.renderMarkup(PageRenderQueueImpl.java:62)
at org.apache.tapestry5.corelib.components.AjaxFormLoop$10.renderMarkup(AjaxFormLoop.java:416)
at
........
fantify 2011-01-12
似乎是你的AjaxFormLoop不在Form组件中?
foollb 2011-01-12
fantify 写道
似乎是你的AjaxFormLoop不在Form组件中?

没,是放到form组件中的:

tml内容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<h1>AjaxFormLoop (1)</h1>
	
	An AjaxFormLoop used that gives full CRUD functionality (Create, Review, Update, and Delete).<br/>
	The changes are not persisted to the database until the Save button is pressed.<br/><br/>

<form t:type="form" t:id="myForm">
		<t:errors/>
		<table>
			<thead>
				<tr>
					<th>Id</th>
					<th>employeeNumber</th>
					<th>sex</th>
					<th>Action</th>
				</tr>
			</thead>
			<tbody>
				<tr t:type="AjaxFormLoop" t:source="emps" t:value="empM" t:encoder="encoder">
					<t:submitnotifier>
						<td>${empM.employeeId}</td>
						<td><input t:type="TextField" t:id="employeeNumber" t:value="empM.employeeNumber" t:validate="required, maxlength=10" size="10"/></td>
						<td><input t:type="TextField" t:id="sex" t:value="empM.sex" t:validate="required, maxlength=10" size="10"/></td>
						<td><t:removerowlink >remove</t:removerowlink></td>
					</t:submitnotifier>
					<p:addRow>
					<td colspan="5" style="text-align: right">
						<t:addrowlink>Add a row</t:addrowlink>
					</td>
					</p:addRow>
				</tr>
			</tbody>
	 	</table>
	 	<input type="submit" value="Save"/>
	</form>

</html>


java内容:
@SuppressWarnings({"unused","unchecked"})
public class AjaxForLoop {

	@Inject
	private BusinessCenter4Admin bc4Admin ;
	
	@Property
	@Persist
	private List<FbpEmployees> empList ;
	
	@Property
	private FbpEmployees empM ;
	
	
	@Property
	private ValueEncoder encoder = new ValueEncoder<FbpEmployees>() {
		public String toClient(FbpEmployees e) {
			Long empId = e.getEmployeeId();
			return empId == null ? "" : empId.toString();
		}
		public FbpEmployees toValue(String clientValue) {
			Long empId = Long.valueOf(clientValue);
			for(FbpEmployees e : empList){
				if(e.getEmployeeId().equals(empId)){
					return e ;
				}
			}
			throw new IllegalArgumentException("Received key \"" + empId
					+ "\" which has no counterpart in this collection: " + empList);
		}
	};
	
	public List<FbpEmployees> getEmps(){
		if(empList == null){
			empList =  bc4Admin.admin__testAjaxForLoop(null);
		}
		return empList ;
	}
	
	void pageAttached(){
		if(empM == null ){
			empM = new FbpEmployees();
		}
	}
	
	void onRemoveRow(FbpEmployees emp) {
		Long empId = emp.getEmployeeId();
		if(empList!=null && empList.size()>0){
			for(FbpEmployees e : empList){
				if(e.getEmployeeId().equals(empId)){
					empList.remove(e);
					return ;
				}
			}
		}
	}
	
	FbpEmployees onAddRow() {
		// Create a skeleton Person and add it to the displayed list with a unique key
		FbpEmployees newEmp = new FbpEmployees();
		newEmp.setSex("girl");
		newEmp.setEmployeeNumber("addNum");
		newEmp.setEmployeeId( 0 - System.nanoTime());
		empList.add(newEmp);
		
		return newEmp;
	}
}


项目中要急用,麻烦仁兄帮忙看下,这个我仿照官网上写的一个例子:
官网例子参见:http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/ajaxformloop1

谢了!
fantify 2011-01-13
表面看不出什么错误的地方。

能不能详细说说错误是哪个步骤产生的?是页面第一次渲染时候还是点击add a row或是remove产生的?

另外你的版本是T5.1?我看到stacktrace中跟最新的t5源代码的调用层次不太对了。
foollb 2011-01-13
fantify 写道
表面看不出什么错误的地方。

能不能详细说说错误是哪个步骤产生的?是页面第一次渲染时候还是点击add a row或是remove产生的?

另外你的版本是T5.1?我看到stacktrace中跟最新的t5源代码的调用层次不太对了。

嗯,是T5.1,问题不是渲染的时候产生的,是在点击add a row 的时候产生的,你可以把代码copy过去测试一下。
看能不能重现问题。
谢谢关注!
seris 2011-01-13
不是说5.1.0.5的ajaxformloop的addrowlink有bug么?那个bug好像有时出现有时不出现,5.1.0.8和5.2修复了
foollb 2011-01-14
seris 写道
不是说5.1.0.5的ajaxformloop的addrowlink有bug么?那个bug好像有时出现有时不出现,5.1.0.8和5.2修复了

啊,这样呀。现在我这个问题,在我本地就是报错的,但是我叫我同事更新工程到他们机子上跑,能够达到预期效果,或者用我同事的浏览器访问我本地的部署环境也是可以的。我机子上所有的浏览器都试过了,就是报错。如果这是5.1.0.5的bug。我就恨我们的设计师了,呵呵,为什么不选个好点的版本。
hxzon 2011-01-14
有5.1.0.8版本???
seris 2011-01-14
hxzon 写道
有5.1.0.8版本???

https://issues.apache.org/jira/browse/TAP5-733
JIRA上是这么说的。。。
lya_love 2011-01-23
我的 没错 嘻嘻
Global site tag (gtag.js) - Google Analytics