[英]Apache Wicket - Form not being submitted
很簡單,我單擊具有type="submit"
的輸入,並且不提交表單。
我已經搜索了此問題的解決方案,但他們說我應該檢查我是否有嵌套表單,而我沒有,只是使用了一個。 他們還說這可能是放錯了位置的標記,但是我已經遍歷整個HTML,並且標記很好。
我在HTML中有以下代碼塊:
<div id="form-options-div" style="margin-top:10px;">
<input class="btn btn-primary" type="submit" wicket:id="saveClientButton" id="save-client-button" />
<input class="btn" type="button" id="close-client-button" wicket:id="closeClientButton"/>
</div>
我在Java代碼中使用AjaxButton
表示saveClientButton
。
我重寫onSubmit(AjaxRequestTarget, Form<?>)
。 我會發布整個Java代碼,但是在方法的開頭有一個記錄器,以查看是否被調用:
logger.debug("ON SUBMIT");
因此它不在方法內部。 有趣的是,當我重寫Form onSubmit()
方法而不是AjaxButton方法時,頁面實際上會重新加載。 但僅此而已,仍未調用onSubmit方法。
為什么會這樣呢?
編輯:
private Button saveClientBtn;
saveClientBtn = new AjaxButton(WICKET_ID_SAVE_CLIENT_BUTTON) {
@Override
public void onError() {
logger.debug("Error on submit...");
}
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
//code....
}
};
closeClientButton
會干擾正常行為? 我不知道,因為按鈕類型是button
,而不是submit
。
editClientForm = new Form<Client>(WICKET_ID_EDIT_CLIENT_FORM);
add(editClientForm);
editClientForm.add(saveClientBtn);
編輯2:
好的,我決定不使用形式onSubmit()
和onError()
,而不是使用AjaxButton。 單擊按鈕時,我看到調用了onError()
。 現在,我需要找到原因。
好的,我放了一個FeedbackPanel。 它給了我以下信息:
'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.
此外,該錯誤還會出現4次,如下所示:
'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.
'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.
'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.
'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.
此錯誤是什么意思?
確保您有一個表單標簽。
例如:
<html>
<body>
<form wicket:id="form">
<div wicket:id="registration">
Display the RegistrationInputPanel
</div>
<input type=”submit” wicket:id="register" value="Register"/>
</form>
</body>
</html>
和java類:
public class RegistrationPage extends Page {
public RegistrationPage(IModel<Registration> regModel) {
Form<?> form = new Form("form");
form.add(new RegistrationInputPanel("registration", regModel);
form.add(new SubmitButton("register") {
public void onSubmit() {
}
});
add(form);
}
}
就我而言,似乎我沒有在表單中設置“必需”值。
這是通過向表單對象添加“ onError”方法來確定的(確定,onError被調用,您可以告訴“什么”錯誤是
String responseTxt = wicketTester.getLastResponse().getDocument();
並通過它查找錯誤消息。
就我而言,實際設置值是
FormTester formTester = wicketTester.newFormTester("formName");
formTester.setValue("requiredElementName", "value");
然后按預期在測試中開始調用onSubmit
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.