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

<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

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. 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. You can pass a single parameter or multiple parameters (using context='[param1, param2]') and then in the submit handler you can use

Object onSubmitFromMyForm(Object param1, Object param2){
....
}

Please note, the parameters are type coerced.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top