Tuesday, June 23, 2009

Tapestry5 - How to handle multiple submit buttons on a form

In yourpage.tml:

<t:form t:id="multiSubmitForm">
<input t:type="submit" t:id="OKButton" value="OK"/>
<input t:type="submit" t:id="CancelButton" value="Cancel"/>
<input t:type="submit" t:id="HelpButton" value="Help"/>
</t:form>


In yourpage.java:

private Class nextPage;

Object onSubmitFromMultiSubmitForm(){
return nextPage;
}

@OnEvent(value="selected", component="OKButton")
void onOKButton(){
.... code ...
nextPage = OKPage.class;
}

@OnEvent(value="selected", component="CancelButton")
void onCancelButton(){
.... code ...
nextPage = CancelPage.class;
}

@OnEvent(value="selected", component="HelpButton")
void onHelpButton(){
.... code ...
nextPage = HelpPage.class;
}

No comments:

Post a Comment