嗨,我遇到一些错误问题:
我尝试使用上下文从一个页面通过页面链接另一个页面传递值整数..代码如下所示:
public class Contact
{
@Persist
@Property
private Integer nNumb;
@Property
private Integer singleRow;
@Property
private Integer singleColumn;
@Persist
@Property
private Integer columns [];
@Persist
@Property
private Integer rows [];
@OnEvent
Object onSumbit(){
rows = new Integer[nNumb];
for (int i = 0; i < nNumb; i++) {
rows[i] = i++;
}
columns = new Integer[nNumb];
for (int i = 0; i < nNumb; i++) {
columns[i] = i++;
}
return null;
}
public Integer getMultiplyValue(){
return singleRow * singleColumn;
}
}
页面 Contact.tml:
<body>
<h1>Multiply Table Page 2</h1>
<p> Submit integer number N (1<=N<=20): </p>
<t:form t:id="userInput">
<p>
<t:label for="nNumb"/>
<t:textfield t:id="nNumb" t:label="N: " t:value="nNumb" t:validate="required,min=1,max=20" />
</p>
<p>
<t:submit t:id="calculate" value="create multy table"/>
</p>
</t:form>
<h1>Result:</h1>
<table border="1">
<tr>
<td bgcolor="#aaaaaa">*</td>
<td bgcolor="#aaaaaa" t:type="loop" t:source="columns" t:value="singleColumn">
${singleColumn}
</td>
</tr>
<tr t:type="loop" t:source="rows" t:value="singleRow">
<td bgcolor="#aaaaaa">${singleRow}</td>
<td t:type="loop" t:source="columns" t:value="singleColumn">
<a href="#" t:type="PageLink" t:page="product" t:context="${multiplyValue}">*</a>
</td>
</tr>
</table>
</body>
pagelink 在第 34 行抛出异常:
Render queue error in BeginRender[Contact:pagelink]: Failure reading parameter 'context' of component Contact:pagelink: org.apache.tapestry5.ioc.internal.util.TapestryException
<小时/>
32 <td bgcolor="#aaaaaa">${singleRow}</td>
33 <td t:type="loop" t:source="columns" t:value="singleColumn">
34 <a href="#" t:type="PageLink" t:page="product" t:context="${multiplyValue}">*</a>
35 </td>
36 </tr>
出了什么问题,我是否正确调用了multiplyValue方法?
最佳答案
我相信上下文几乎总是期望“值”是属性名称,而不是表达式。所以你想要:
t:context="multiplyValue"
而不是
t:context="${multiplyValue}"
我认为它会执行表达式,然后将其转换为字符串(这通常发生在上下文参数中?但话又说回来,存在错误,所以也许不会。
更新:(来自评论中的提问者) 嗨!我发现了问题所在......当我输入 rows[i]=i++; 时,问题出在 onSubmit() 方法中;并且 columns[i]=i++ 这是错误的......我必须这样做: rows[i]=i+1;列[i]= i+1
我想我应该仔细阅读代码:)
关于java - 页面链接读取参数 'context' 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6372918/