You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sergey Podatelev <br...@gmail.com> on 2008/04/02 09:06:21 UTC

How to listen to other component's events?

Hello Wicket people,

I have a user registration page with a couple of dropdown lists on it.
Elements of those lists are alphabetically sorted.
Also, there's a language selector on each page of the application, so
there's also one on the registration page.
The problem is, when user changes language via selector, all dropdown lists
must be reordered to keep being alphabetically sorted.

I guess I have to re-construct my DropDownChoice components for this, but
I'm not sure how to notify the page of the language change event. Can I
somehow make the form on the registration page listen to an unrelated
component's onChange event?


-- 
sp

Re: How to listen to other component's events?

Posted by Sergey Podatelev <br...@gmail.com>.
Thanks Maurice, that reduced my code to two lines :).


On Wed, Apr 2, 2008 at 12:19 PM, Maurice Marrink <ma...@gmail.com> wrote:

> You should not set a list directly on your dropdown but load it using
> for example a loadabledetachable model.
>
> Maurice



-- 
sp

Re: How to listen to other component's events?

Posted by Maurice Marrink <ma...@gmail.com>.
You should not set a list directly on your dropdown but load it using
for example a loadabledetachable model, that way your getCountriesList
method is executed every time the component is rendered.

Maurice

On Wed, Apr 2, 2008 at 10:12 AM, Sergey Podatelev
<br...@gmail.com> wrote:
> Thanks for quick reply, Nino.
>
>  No, I'm not using ajax so far.
>
>  Let me describe a bit more: there's a registration page, which has a
>  RegisterForm. Also, the page has an OptionsPanel unrelated to the
>  RegisterForm with a language selector DDC. That DDC is bound to Session's
>  "language" property via PropertyModel. What I want is to reorder items in
>  RegisterForm's DDCs.
>
>  I've actually implemented it this way (list of countries is one of the lists
>  that must be reordered):
>
>  OptionsPanel:
>
>  add(new DDC(...) {
>   onSelectionChanged() {
>     ...
>     ((BasePage) getPage()).notifyLanguageSwitch();
>   }
>  });
>
>
>  RegisterPage:
>
>  RegisterPage extends BasePage {
>
>   init() {
>   ...
>     processLocaleSpecificComponents();
>   ...
>   }
>
>   notifyLanguageSwitch() {
>     processLocaleSpecificComponents();
>   }
>
>   processLocaleSpecificComponents() {
>
>     Component countriesChoice = get("countryChoice");
>
>     DDC newCountriesChoice = new DDC("countryChoice",
>  getCountriesList(getLanguageId()), new ChoiceRenderer(...));
>
>     if (countriesChoice != null) {
>       countriesChoice.replaceWith(newCountriesChoice);
>     } else {
>       add(countriesChoice);
>     }
>   }
>  }
>
>  But you're saying, I don't have to reconstruct components. How can I control
>  order of items in the DDC then? Even though data is provided dynamically,
>  like this:
>
>  add(new DropDownChoice("countryChoice", getCountriesList(getLanguageId()),
>  new ChoiceRenderer("name", "id"));
>
>  the getCountriesList() method isn't called when page is reloaded to switch
>  language.
>
>
>
>  On Wed, Apr 2, 2008 at 11:14 AM, Nino Saturnino Martinez Vazquez Wael <
>  nino.martinez@jayway.dk> wrote:
>
>  you could use call modelchanged on the forms model. Or make the components
>  > take an ajaxrequesttarget, depending if youre using ajax?
>  >
>  > You should'nt have to reconstruct them. But that depends if youre using
>  > models or not etc..
>  >
>
>
> > The problem is, when user changes language via selector, all dropdown
>  > > lists
>  > > must be reordered to keep being alphabetically sorted.
>  > >
>  > > I guess I have to re-construct my DropDownChoice components for this,
>  > > but
>  > > I'm not sure how to notify the page of the language change event. Can I
>  > > somehow make the form on the registration page listen to an unrelated
>  > > component's onChange event?
>  > >
>  >
>  --
>  sp
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to listen to other component's events?

Posted by Sergey Podatelev <br...@gmail.com>.
Thanks for quick reply, Nino.

No, I'm not using ajax so far.

Let me describe a bit more: there's a registration page, which has a
RegisterForm. Also, the page has an OptionsPanel unrelated to the
RegisterForm with a language selector DDC. That DDC is bound to Session's
"language" property via PropertyModel. What I want is to reorder items in
RegisterForm's DDCs.

I've actually implemented it this way (list of countries is one of the lists
that must be reordered):

OptionsPanel:

add(new DDC(...) {
  onSelectionChanged() {
    ...
    ((BasePage) getPage()).notifyLanguageSwitch();
  }
});


RegisterPage:

RegisterPage extends BasePage {

  init() {
  ...
    processLocaleSpecificComponents();
  ...
  }

  notifyLanguageSwitch() {
    processLocaleSpecificComponents();
  }

  processLocaleSpecificComponents() {

    Component countriesChoice = get("countryChoice");

    DDC newCountriesChoice = new DDC("countryChoice",
getCountriesList(getLanguageId()), new ChoiceRenderer(...));

    if (countriesChoice != null) {
      countriesChoice.replaceWith(newCountriesChoice);
    } else {
      add(countriesChoice);
    }
  }
}

But you're saying, I don't have to reconstruct components. How can I control
order of items in the DDC then? Even though data is provided dynamically,
like this:

add(new DropDownChoice("countryChoice", getCountriesList(getLanguageId()),
new ChoiceRenderer("name", "id"));

the getCountriesList() method isn't called when page is reloaded to switch
language.


On Wed, Apr 2, 2008 at 11:14 AM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> wrote:

you could use call modelchanged on the forms model. Or make the components
> take an ajaxrequesttarget, depending if youre using ajax?
>
> You should'nt have to reconstruct them. But that depends if youre using
> models or not etc..
>
> The problem is, when user changes language via selector, all dropdown
> > lists
> > must be reordered to keep being alphabetically sorted.
> >
> > I guess I have to re-construct my DropDownChoice components for this,
> > but
> > I'm not sure how to notify the page of the language change event. Can I
> > somehow make the form on the registration page listen to an unrelated
> > component's onChange event?
> >
>
-- 
sp

Re: How to listen to other component's events?

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
you could use call modelchanged on the forms model. Or make the 
components take an ajaxrequesttarget, depending if youre using ajax?

You should'nt have to reconstruct them. But that depends if youre using 
models or not etc..

Sergey Podatelev wrote:
> Hello Wicket people,
>
> I have a user registration page with a couple of dropdown lists on it.
> Elements of those lists are alphabetically sorted.
> Also, there's a language selector on each page of the application, so
> there's also one on the registration page.
> The problem is, when user changes language via selector, all dropdown lists
> must be reordered to keep being alphabetically sorted.
>
> I guess I have to re-construct my DropDownChoice components for this, but
> I'm not sure how to notify the page of the language change event. Can I
> somehow make the form on the registration page listen to an unrelated
> component's onChange event?
>
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org