Reputation: 1729
Simple, I click on the input that has the type="submit"
, and the form isn't submitted.
I've searched solutions to this issue but they say I should check if I have nested forms, which I don't, I'm only using one. They also said it could be some misplaced tag, but I've gone through the whole HTML and the tags are fine.
I have this block in the 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>
I'm using an AjaxButton
in the java code to represent the saveClientButton
.
I'm overriding the onSubmit(AjaxRequestTarget, Form<?>)
. I would post the whole java code, but I have a logger at the start of the method to see if it's being called:
logger.debug("ON SUBMIT");
So it's not inside the method. An interesting thing is that when I override the Form onSubmit()
method, instead of the AjaxButton one, the page actually reloads. But it's only that, the onSubmit method still isn't called.
Why is this happening?
EDIT:
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....
}
};
Could the closeClientButton
be interfering with the normal behavior? I don't know, because the button type is button
, not submit
.
editClientForm = new Form<Client>(WICKET_ID_EDIT_CLIENT_FORM);
add(editClientForm);
editClientForm.add(saveClientBtn);
EDIT 2:
OK, instead of using AjaxButton, I decided to override the Form onSubmit()
and onError()
. When clicking the button, I see that onError()
is called. Now I need to find the reason why.
Ok, I put a FeedbackPanel. It gives me the following message:
'[Page class = EditClientPage, id = 6, render count = 1]' is not a valid EditClientPage.
Also, the error appears 4 times, as in:
'[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.
What does this error means?
Upvotes: 1
Views: 7578
Reputation: 66911
In my case, it appears I was not setting a "required" value within the form.
This was ascertained by adding an "onError" method to the form object (sure enough, onError was being called, you can tell "what" the error was like
String responseTxt = wicketTester.getLastResponse().getDocument();
And dig through it to look for the error message.
To actually set the value, in my case, was
FormTester formTester = wicketTester.newFormTester("formName");
formTester.setValue("requiredElementName", "value");
Then the onSubmit
method started being called within tests, as was expected.
Upvotes: 1
Reputation: 698
Make sure you have a form tag.
e.g.:
<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>
and the java class:
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);
}
}
Upvotes: 1