gpt4 book ai didi

Tapestry5 : handling multiple submit buttons with form validation event

转载 作者:行者123 更新时间:2023-12-04 11:42:27 24 4
gpt4 key购买 nike

在 Tapestry5 中,表单中有两个提交按钮,我也想执行验证事件,我该如何实现?这就是我想要做的:

在 page.tml

<form t:type="form" t:id="verifyCreateExampleModelForm">

<input class="btsubmit" t:type="submit" t:id="saveAsAwaitingCompletion" >
<input class="btsubmit" t:type="submit" t:id="saveAsCreated">
</form>

在 page.class 中
@OnEvent(value = EventConstants.VALIDATE_FORM, component = "verifyCreateExampleModelForm")
private Object validation() {
if (StringUtils.isEmpty(modelTypeName)) {
verifyCreateExampleModelForm.recordError("incorrectmodelTypename"));
this.isAllowed = false;
}
}

@OnEvent(component = "saveAsAwaitingCompletion", value = "selected")
private void onSaveAsAwaitingCompletion() {
}

@OnEvent(component = "saveAsCreated", value = "selected")
private void onSaveAsCreated() {
}

最佳答案

正如您所观察到的,selected事件在验证之前发生,因此您不能将操作处理程序代码放入提交按钮的事件处理程序中。但是,您可以在这些方法中存储状态并在表单事件处理程序中执行实际操作:

@OnEvent(component = "saveAsAwaitingCompletion", value = EventConstants.SELECTED)
void saveAsAwaitingCompletionClicked() {
this.action = AWAITING_COMPLETION;
}

@OnEvent(component = "saveAsCreated", value = EventConstants.SELECTED)
void saveAsCreatedClicked() {
this.action = CREATED;
}

... //validation logic etc.

@OnEvent(component="verifyCreateExampleModelForm" value = EventConstants.SUCCESS)
void save() {
if (this.action == AWAITING_COMPLETION) {
...
} else {
...
}
}

关于Tapestry5 : handling multiple submit buttons with form validation event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9431794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com