To avoid changing wantSubmitOnParentFormSubmit visibility we can use
isSubmitted to check if the target form has been submitted:
@Override
protected void onEvent(final AjaxRequestTarget target)
{
AjaxFormSubmitBehavior.AjaxFormSubmitter submitter = new
AjaxFormSubmitBehavior.AjaxFormSubmitter(this, target);
Form<?> form = getForm();
form.getRootForm().onFormSubmitted(submitter);
if (!form.isSubmitted())
{
form.onFormSubmitted(submitter);
}
}
On Mon, Aug 21, 2017 at 1:22 PM, Vit Rozkovec <[email protected]> wrote:
> Hi,
> this may be a naive solution that I did not have the time to test yet, but
> wouldn't this change make at least inner form ajax-submit enabled?
>
> @Override
> protected void onEvent(final AjaxRequestTarget target)
> {
> Form<?> form = getForm();
> if(!form.wantSubmitOnParentFormSubmit())
> form.onFormSubmitted(new
> AjaxFormSubmitBehavior.AjaxFormSubmitter(this,
> target));
> form.getRootForm().onFormSubmitted(new
> AjaxFormSubmitBehavior.AjaxFormSubmitter(this, target));
> }
>
> It would mean to make Form's wantSubmitOnParentFormSubmit() public, though.
> The point is to mark inner form as submitted via markFormsSubmitted() that
> is private at the moment, so then in root form's onFormSubmitted >
> formToProcess.process(submitter) > delegateSubmit(submittingComponent) >
> Visits.visitPostOrder(...) the inner form is collected and inner form's
> onSubmit is called.
>
> Vit
>
> On 08/21/2017 11:35 AM, Andrea Del Bene wrote:
>
>> Hi,
>>
>> this is somehow related to WICKET-6041
>> <https://issues.apache.org/jira/browse/WICKET-6041>. Unfortunately we
>> couldn't find a solution for this old issue.
>>
>> On Mon, Aug 21, 2017 at 12:55 AM, Vit Rozkovec <[email protected]>
>> wrote:
>>
>> Hi,
>>>
>>> I think I have discovered a bug where inner form, when set
>>> wantSubmitOnParentFormSubmit() to false, does not get submitted when used
>>> with AjaxButton. Normal SubmitLink works.
>>>
>>> Please see attached quickstart for demonstration.
>>>
>>> I believe the problem is in Form's onFormSubmitted(IFormSubmitter
>>> submitter) and markFormsSubmitted()
>>>
>>> When used with Ajax, onFormSubmitted gets called for parent form in
>>> AjaxFormSubmitBehavior:
>>>
>>> * @Override*
>>> * protected void onEvent(final AjaxRequestTarget target)*
>>> * {*
>>> * getForm().getRootForm().onFormSubmitted(new
>>> AjaxFormSubmitBehavior.AjaxFormSubmitter(this, target));*
>>> * }*
>>>
>>> onFormSubmitted calls markFormsSubmitted but this implementation:
>>>
>>> * private void markFormsSubmitted()*
>>> * {*
>>> * setFlag(FLAG_SUBMITTED, true);*
>>>
>>> * visitChildren(Form.class, new IVisitor<Component, Void>()*
>>> * {*
>>> * @Override*
>>> * public void component(final Component component, final
>>> IVisit<Void> visit)*
>>> * {*
>>> * Form<?> form = (Form<?>)component;*
>>> * if (form.wantSubmitOnParentFormSubmit() &&
>>> form.isEnabledInHierarchy() && form.isVisibleInHierarchy())*
>>> * {*
>>> * form.setFlag(FLAG_SUBMITTED, true);*
>>> * return;*
>>> * }*
>>> * visit.dontGoDeeper();*
>>> * }*
>>> * });*
>>> * }*
>>>
>>> skips the inner form with wantSubmitOnParentFormSubmit set to false.
>>>
>>> Further down the road delegateSubmit collects forms that have been
>>> submitted, but as this inner form was skipped and flag was not set, it
>>> does
>>> not call form's onSubmit method.
>>>
>>> My use case is having one large form and ajax subform that works as
>>> add/list comments form for parent large form.
>>>
>>> Am I missing something?
>>>
>>> Thanks for looking into it.
>>>
>>> Vit
>>>
>>>
>