开发者

Wicket ListMultipleChoice and ajax

I have a question about the ListMultipleChoice, is there anyway to get the selected items before the submit by an ajax link for example because i wouldn't refresh my page every time.

Thanks!

    // Liste des partenaires de l'offre.
final ListMultipleChoice partenairesSelec =
    new ListMultipleChoice("partenairesSelec", new Model((Serializable) partenairesSelected), new PropertyModel(
        offre,
        "partenaires"), renderer);


// Liste des domaines.
final DropDownChoice makes = new DropDownChoice("domaines", new PropertyModel(this, "selectedMake"), makeChoices) {
  @Override
  protected CharSequence getDefaultChoice(Object selected) {
    return new ArrayList<String>(modelsMap.keySet()).get(0);
  }
};

// Liste des partenaires disponibles.
final ListMultipleChoice partenairesChoice =
    new ListMultipleChoice("partenaires", new Model((Serializable) partenairesSelection), modelChoices, renderer);


// Action associé au changement du domaine.
makes.add(new AjaxFormComponentUpdatingBehavior("onchange") {
  @Override
  protected void onUpdate(AjaxRequestTarget target) {
    target.addComponent(partenairesChoice);
  }
});

// Bouton ajouter.
Button ajout = new Button("ajout") {
  @Override
  public void onSubmit() {
    if (partenairesSelection.size() != 0) {
      for (Partenaire p : partenairesSelection) {
        if (!partenairesSelected.contains(p)) {
          offre.getPartenaires().add(p);
          modelsMap.get(selectedMake).remove(p);
        }
      }
      offre.setPartenaires(sortPartenaireList(offre.getPartenaires()));
    }
  }
};

// Bouton supprimer.
Button suppr = new Button("suppr") {
  @Override
  public void onSubmit() {
    List<Partenaire> tmp = new ArrayList<Partenaire>();
    if (partenairesSelected.size() != 0) {
      for (Partenaire p : partenairesSelected) {
        if (!partenairesSelection.contains(开发者_运维知识库p)) {
          Long id = p.getPartnerDomainId();
          tmp.add(p);
          for (String key : modelsMap.keySet()) {
            if (modelsMap.get(key).size() > 0 && modelsMap.get(key).get(0).getPartnerDomainId() == id) {
              modelsMap.get(key).add(p);
            }
          }
        }
      }
      for (Partenaire p : tmp) {
        offre.getPartenaires().remove(p);
      }
      offre.setPartenaires(sortPartenaireList(offre.getPartenaires()));
    }
  }
};


AjaxFormChoiceComponentUpdatingBehavior is the class designed to do just that. Attach it to your component and you'll get AJAX updates wherever the selection changes.


AjaxFormChoiceComponentUpdatingBehavior does not work for ListMultipleChoice!

I also searched for a good working solution and after a while I found a really good tutorial facing exactly a situation with two ListMultipleChoice elements and add/remove buttons to exchange contents between the two multiple select boxes:
http://blog.xebia.com/2008/03/25/wicket-and-list-choice-transfers/

They use AjaxButtons for doing this without submitting the form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜