Note that there are some explanatory texts on larger screens.

plurals
  1. POWicket Dependency Injection
    primarykey
    data
    text
    <p>I've got a page with a form in Wicket where the form requires a collaborator to get its job done. The collaborator is injected (for which I'm using Guice) and looks something like:</p> <pre><code>public class RegistrationPage extends WebPage { @Inject public RegistrationPage(RegistrationService service) { this.service = service; add(new RegistrationForm()); } private class RegistrationForm extends Form { public RegistrationForm() { // setup } protected void onSubmit() { service.doSomething(); } } } </code></pre> <p>I don't like the idea that the RegistrationService is injected into the RegistrationPage when it's just the RegistrationForm that needs it. I could change the RegistrationForm to receive the RegistrationService:</p> <pre><code>public RegistrationForm(RegistrationService service) { this.service = service; } </code></pre> <p>and remove the field from the RegistrationPage, but the RegistrationPage is still being used to do the pass-through.</p> <p>I guess what I'm asking is what the best-practise is for doing this? Is this ok to do, or would it perhaps be better to inject the RegistrationForm itself into the Page:</p> <pre><code> public class RegistrationPage extends WebPage { @Inject public RegistrationPage(RegistrationForm form) { add(form); } } --- private class RegistrationForm extends Form { private RegistrationService service; @Inject public RegistrationForm(RegistrationService service) { this.service = service; } protected void onSubmit() { service.doSomething(); } } </code></pre> <p>I'd prefer this as I'd like to have the RegistrationForm in a separate class/file. I'm quite new to Wicket so unsure of what the norm is - can someone show me the guiding light? :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload