Re: Forms: Radio and RadioGroup in multiple data row items

andrew goh <[email protected]>
Newsgroups gmane.comp.java.wicket.user,gmane.text.xml.xalan.devel
Message-ID <[email protected]>
it turns out the ListView need not be added to the RadioGroup, but that 
when creating the Radio<> object, the radio group object needs to be 
passed and that works just well.
so it looks like:

public class MyObject {
   private Integer myInt;
   public void setMyInt(Integer myInt) ...
   public Integer getMyInt() ...
}
MyObject bean=new MyObject();
RadioGroup radioGroup = new RadioGroup("group", new PropertyModel(bean, 
"myInt"));
add(radioGroup);

List<Integer> items = new ArrayList<>();
items.add(1);
items.add(2);

add(new ListView<Integer>("ListView", items) {

     @Override
     protected void populateItem(ListItem<Integer> item) {

         Integer value = item.getModelObject();

         Radio<String> radio = new Radio<>("radio", 
Model.of(Integer.toString(value)), radioGroup);
         item.add(radio);

     }

}

<wicket:container wicket:id="group"></wicket:container>
<wicket:container wicket:id="ListView">
     <input type="radio" wicket:id="radio">
</wicket:container>

If that is the case, multiple radio groups can be used, just pass them 
(the radio group) when creating the Radio<> object.

On 31/07/2025 20:29, andrew goh wrote:
>
> Recently I've a requirement that I need to have a radio button 
> selection across multiple row items.
>
> I found some documentation for use of Radio and RadioGroups like this
>
> https://cwiki.apache.org/confluence/display/WICKET/Using+RadioGroups
> public class MyObject {
>   private Integer myInt;
>   public void setMyInt(Integer myInt) ...
>   public Integer getMyInt() ...
> }
>
> MyObject bean=new MyObject();
> RadioGroup myInt = new RadioGroup("group", new PropertyModel(bean, 
> "myInt"));
> myInt.add(new Radio("1", new Model(1)));
> myInt.add(new Radio("2", new Model(2)));
> myInt.add(new Radio("3", new Model(3)));
> myInt.add(new Radio("4", new Model(4)));
> add(myInt);
>
>
> <span wicket:id="group">
>   <input wicket:id="1" type="radio"/>
>   <input wicket:id="2" type="radio"/>
>   <input wicket:id="3" type="radio"/>
>   <input wicket:id="4" type="radio"/>
> </span>
>
> However, this is for within the same (row) data item. While I worked 
> things out it turns out that it is feasible to have radio  items and 
> radio  groups in a ListView.
> But that is is *tricky* like such:
>
> List<Integer> items = new ArrayList<>();
> items.add(1);
> items.add(2);
>
> MyObject bean=new MyObject();
> RadioGroup radioGroup = new RadioGroup("group", new 
> PropertyModel(bean, "myInt"));
> add(radioGroup);
>
> radioGroup.add(new ListView<Integer>("ListView", items) {
>
>     @Override
>     protected void populateItem(ListItem<Integer> item) {
>
>         Integer value = item.getModelObject();
>
>         Radio<String> radio = new Radio<>("radio", 
> Model.of(Integer.toString(value)), radioGroup);
>         item.add(radio);
>
>     }
>
> }
>
> <wicket:container wicket:id="group">
> <wicket:container wicket:id="ListView">
>     <input type="radio" wicket:id="radio">
> </wicket:container>
> </wicket:container>
>
> a few things, I think this could be useful to add in the documents as 
> examples.
> the key is that the listview is added to the radio group  !
>
> But that then I've a doubt / question.
>
> If you review docs for the html element radio e.g.
>
> https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/radio
>
> radio  groups is not specifically an element, radio groups are 
> semantic in that <input type="radio"> elements forms a group
> if they  have the  same /name/ .
>
> Then my doubt is that if I've 2 distinct radio groups, in the same 
> list view say one is for 'select' and another for 'default', I'm 
> wondering how that can be achieved?
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.