Gate. Can a panel or component respond to a form without any patterns?

I am currently evaluating Wicket and I am trying to figure out how everything works.

I have a question regarding the presentation of forms and panels (or other components). Imagine a customizable wicket panel that contains a text box, doing a type check on your type with ajax. This panel is added to the form. How does the panel respond to form submission (say, because javascript / ajax is not available)?

Currently, I know only one solution: calling the panel method inside the Form onSubmit () method. But here, this does not look like a “reusable” approach, because I have to add boilerplate code to every onSubmit () form that contains the panel (and every developer who uses the panel should know this).

So here is my question: is there a way that Panel / Component can "detect" a form in some form? Or is there another solution next to this?

Thanks.

+4
source share
6 answers

Make your panels an implementation of org.apache.wicket.markup.html.form.IFormModelUpdateListener , and the updateModel() method should be called when the containing form is submitted and validated.

There's a good code example using this one of the authors of the gate on the Wicket In Action blog.

+6
source

Well, you could just do the following:

 Panel{ Form{ onSubmit(){ Panel.this.onSubmit(); } } protected void onSubmit(){} } 

...

This means that any panel that extends your panel should only override onSubmit, and the form, regardless of what it is in html, will call this method. Thus, you can expand the panel and only override one method for each form.

+1
source

As for the components of the form, the platform processes it transparently for you. Forms are aware of any components of the child form, even if they were not added directly to the parent form.

0
source

I would have a form inside this panel. Thus, you can reuse this panel without requiring an external form. Since forms cannot be embedded within each other in HTML, Wicket will exchange the internal form transparently, but will ensure that each of the internal forms takes part in the processing of the form (validation, ..).

You can override the OnSubmit () function of the form in your panel. Wicket will call him for you.

0
source

what do you mean by "reaction"? I just started working with Wicket, but FWIK, form submit updates the component model and then calls onSubmit() , which you can override to perform special actions beyond this. See Wicket in Action, Chapter 6.

After that, the page (and its components) gets re-rendered using the updated model, so basically they really "respond" to submit with a fairly small number of lines of code.

For your mentioned case with a component in the form, check out CompoundPropertyModel .

0
source

The implementation of IFormSubmitListner and IFormModelUpdateListener should call the appropriate methods while submitting the form.

However, if you want to do some processing after submitting the form, I am afraid that you have no choice but to write your own template code.

0
source

Source: https://habr.com/ru/post/1311615/


All Articles