Wicket调色板和选择

时间:2011-07-27 21:18:32

标签: wicket

我有一个与选项列表相关联的调色板,问题是在我从该列表中选择2个值之后,选项列表(左侧)消失了!请你知道这个(我做了一个调试,我看到了choiceModel正确设置!!)这里我的代码:

List<Partenaire> toutPartenaires = partenaireHelper.getPartenaires(StatusType.ACTIF);
final IChoiceRenderer renderer = new ChoiceRenderer("nom", "identifiant");

final List<Partenaire> partenairesPossibles = new ArrayList<Partenaire>();
final List<Partenaire> partenairesExistants = offre.getPartenaires();

// if (partenairesExistants != null && partenairesExistants.size() > 0)
for (Partenaire p : toutPartenaires) {
  if (!partenairesExistants.contains(p)) {
    partenairesPossibles.add(p);
  }
}

// Date de la dernière diffusion.
SimpleDateFormat dateStandard = new SimpleDateFormat("dd/MM/yyyy");
add(new Label("dateDiffusion", dateStandard.format(offre.getDateDepublication())));

List<PartnerDomainDTO> domaines = partenaireHelper.allDomains();

if (domaines != null && domaines.size() > 0) {
  for (PartnerDomainDTO domaine : domaines) {
    modelsMap.put(domaine.getLabel(), partenaireHelper.recherchePartenairesDomain(
        domaine.getSid(),
        StatusType.ACTIF));
  }
}

IModel makeChoices = new AbstractReadOnlyModel() {
  @Override
  public List<String> getObject() {
    return new ArrayList<String>(modelsMap.keySet());
  }

};

final IModel modelChoices = new AbstractReadOnlyModel() {
  @Override
  public List<Partenaire> getObject() {
    List<Partenaire> models = modelsMap.get(selectedMake);
    if (models == null) {
      models = Collections.emptyList();
    }
    return models;
  }

};

final DropDownChoice makes = new DropDownChoice("domaines", new PropertyModel(this, "selectedMake"), makeChoices);
palette1 = new Palette("partenaires", new PropertyModel(offre, "partenaires"), modelChoices, renderer, 10, false) {

  @Override
  public Iterator getSelectedChoices() {
    return offre.getPartenaires().iterator();
  }

  @Override
  protected Recorder newRecorderComponent() {
    final Recorder recorder = super.newRecorderComponent();
    recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {
      @Override
      protected void onUpdate(AjaxRequestTarget target) {
        List<Partenaire> test = new ArrayList<Partenaire>();
        Iterator<Partenaire> selectedChoices = recorder.getSelectedChoices();
        while (selectedChoices.hasNext()) {
          test.add(selectedChoices.next());
        }

        List<Partenaire> tmp = offre.getPartenaires();
        List<Partenaire> choices = (List<Partenaire>) palette1.getChoices();
        Long id = 0L;
        if (choices != null && choices.size() > 0) {
          id = choices.get(0).getPartnerDomainId();
          if (parts != null && parts.size() > 0) {
            for (Partenaire p : parts) {
              if (!tmp.contains(p) && p.getPartnerDomainId() != id) {
                tmp.add(p);
              }
            }
          }

          if (tmp == null) {
            tmp = new ArrayList<Partenaire>();
          }

          List<Partenaire> part = sortPartenaireList(tmp);
          parts.clear();
          for (Partenaire p : part) {
            parts.add(p);
          }
          offre.setPartenaires(part);
        } else if (choices.size() == 0) {
          offre.setPartenaires(parts);
        }
        target.addComponent(palette1);
      }

    });
    return recorder;
  }
};
palette1.setOutputMarkupPlaceholderTag(true);

makes.add(new AjaxFormComponentUpdatingBehavior("onchange") {
  @Override
  protected void onUpdate(AjaxRequestTarget target) {
    parts = new ArrayList<Partenaire>();
    if (offre.getPartenaires() != null && offre.getPartenaires().size() > 0) {
      for (Partenaire p : offre.getPartenaires()) {
        parts.add(p);
      }
    }
    target.addComponent(palette1);
  }
});
add(makes);
add(palette1);

1 个答案:

答案 0 :(得分:0)

您必须使用AjaxFormChoiceComponentUpdatingBehavior代替AjaxFormComponentUpdatingBehavior