hi,
accordingly, it is feasible to have multiple <input type="submit"> buttons:
<input type="submit" name="action" value="update">
<input type="submit" name="action" value="delete">
the parameter action=update or action=delete would be posted to the
server according to the button pressed.
However, in Apache Wicket, the various buttons still run the
Form.onSubmit() method,even if the Button has its own onSubmit(), e.g. :
Button button = new Button {
public UpdateButton("update") {
super(id);
setDefaultFormProcessing(false);
}
@Override
public void onSubmit() {
log.debug("update button clicked");
}
};
add(button);
However, setting default form processing to false, causes all the form
data to be ignored and the submitted data is not bound to the model object.
https://nightlies.apache.org/wicket/guide/9.x/single.html#_disabling_default_form_processing
How do I handle multiple submit buttons if I still need to form data to
be updated into the model object?
Or that at least how do I tell which button is pressed so that say in
the Form.onSubmit(), I can check which other button is pressed and skip
processing that is not relevant to the other button?
at the moment I did an ugly hack by tracking if the button.onSubmit() is
called prior, as the codes goes:
https://github.com/apache/wicket/blob/aa8527ae0aecb4dc43bdbd429c42d7a4373b8312/wicket-core/src/main/java/org/apache/wicket/markup/html/form/Form.java#L1387
// process submitting component (if specified)
if (submittingComponent != null)
{
// invoke submit on component
submittingComponent.onSubmit();
}
// invoke Form#onSubmit(..)
for (Form<?> form : forms)
{
form.onSubmit();
}
my codes look like
public class MyForm extends StatelessForm<Void>> {
private IFormSubmitter submittingComponent;
public MyForm(String id) {
super(id);
this.submittingComponent = null;
Button button = new Button("update") {
@Override
public void onSubmit() {
log.debug(marker, "update button clicked");
submittingComponent = this;
}
}
};
add(button);
}
//this is the form
@Override
public void onSubmit() {
if (submittingComponent != null) {
log.debug("Form.submit(): the other button is clicked : {}",
((Button) this.submittingComponent).getId());
this.submittingComponent = null;
}
}
...
ugly and it depends on that Form.process() code calling the 2
Button.onSubmit() and Form.onSubmit() in sequence.
Is there a better way to tell which button is pressed so as to route
processing?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]