[英]Tapestry - How to pass parameters from tml page to event handler in tapestry?
I am new to tapestry. 我是挂毯的新手。 Can someone help me on following issue I am having hard time solving?
有人可以帮助我解决问题我很难解决问题吗?
I have a form in my page tags.tml 我的页面中有一个表单tags.tml
<div class="tagForm" id="addTagFormElement" style="display:none;">
<t:form t:id="addTagForm" t:zone="tagsZone" class="hideForReadOnlyMode addTagForm" style="display:inline-block;">
<t:textfield t:id="newTag" t:mixins="salsaautocomplete" size="25" placeholder="add a tag" validate="required" value="newTag" />
</t:form>
</div>
When this form is submitted, following method is called on the server side java class tags.java 提交此表单时,在服务器端java类tags.java上调用以下方法
Object onSuccessFromAddTagForm() {
// some logic
}
I want to know how can I pass a parameter(say "testParameter") from tml file to this method which is invoked when the form is submitted. 我想知道如何将参数(比如“testParameter”)从tml文件传递给在提交表单时调用的此方法。 I would like to do something like below.
我想做类似下面的事情。
<div class="tagForm" id="addTagFormElement" style="display:none;">
<t:form t:id="addTagForm" t:zone="tagsZone" t:testParameter="testValue" class="hideForReadOnlyMode addTagForm" style="display:inline-block;">
<t:textfield t:id="newTag" t:mixins="salsaautocomplete" size="25" placeholder="add a tag" validate="required" value="newTag" />
</t:form>
</div>
And access it in method like, 并在方法中访问它,如,
Object onSuccessFromAddTagForm(String testParameter) {
// some logic
}
Use context
parameter of form . 使用表单的
context
参数。 You can pass a single parameter or multiple parameters (using context='[param1, param2]'
) and then in the submit handler you can use 你可以传递一个参数或多个参数(使用
context='[param1, param2]'
),然后在提交处理程序中你可以使用
Object onSubmitFromMyForm(Object param1, Object param2){
....
}
Please note, the parameters are type coerced. 请注意,参数是强制类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.