2014-05-12 3 views
2

Est-il possible d'obtenir le balisage ids de checkgroup à petite porte, j'ai le code suivantWicket CheckGoup obtenir des objets sélectionnés markupIds

Form f = new Form("form"); 
    add(f); 
    final CheckGroup group = new CheckGroup("group", new ArrayList<Person>()); 
    f.add(group); 
    group.add(new CheckGroupSelector("groupselector")); 
    ListView persons = new ListView("persons", getPersons()) { 
     @Override 
     protected void populateItem(ListItem item) { 
      item.add(new Check("checkbox", item.getModel())); 
      item.add(new Label("name", new PropertyModel(item.getModel(), "name"))); 
      item.add(new Label("lastName", new PropertyModel(item.getModel(), "surname"))); 
     } 
    }; 
    persons.setReuseItems(true); 
    group.add(persons); 
    f.add(new AjaxSubmitLink("submit") { 

     @Override 
     protected void onSubmit(AjaxRequestTarget target, Form<?> form) { 
      System.out.println(((List)group.getModelObject()).size()); 
      // need to get group markup ids here 
     } 

    }); 

Toutes les suggestions?

+0

Pourquoi en avez-vous besoin? – Martin

+0

J'ai besoin d'appliquer du code javascript avec la liste des identifiants de balisage sélectionnés. – falconw

Répondre

1

Ceci est la documentation de Component.getMarkupId(). Vous avez donc besoin d'accéder aux composants pour obtenir MarkupId et faire ce que vous voulez faire.

/** 
* Retrieves id by which this component is represented within the markup. This is either the id 
* attribute set explicitly via a call to {@link #setMarkupId(String)}, id attribute defined in 
* the markup, or an automatically generated id - in that order. 
* <p> 
* If no explicit id is set this function will generate an id value that will be unique in the 
* page. This is the preferred way as there is no chance of id collision. 
* <p> 
* Note: This method should only be called after the component or its parent have been added to 
* the page. 
* 
* @return markup id of the component 
*/ 
public String getMarkupId() 
{ 
    return getMarkupId(true); 
} 
+0

group.getMarkupId donne l'ID de balisage du groupe, pas de valeurs sélectionnées – falconw

+1

oui, vous devez appeler la méthode sur les objets ListItem. Vous pouvez les ajouter à une liste ici. – Martin

+0

Ceci est une solution possible, mais je pense que devrait être un meilleur, où vous pouvez obtenir tous les identifiants du groupe de contrôle – falconw

Questions connexes