it turns out I did not solve the issue.
If I leave the radio group on its own (as an orphan), instead of adding
the ListView to it I get an error
Last cause: submitted http post value [radio0] for RadioGroup component
[3:Form:radioGroup] is illegal because it does not point to a Radio
component. Due to this the RadioGroup component cannot resolve the
selected Radio component pointed to by the illegal value. A possible
reason is that component hierarchy changed between rendering and form
submission.
But if I add a rather complex ListView to the radio group, I run into
other issues, e.g. that some deep hierarchy java object cannot be
serialized.
This is really incorrect, but I'm unsure how to go about implementing
radio boxes across item selections as in a ListView or RepeatingView.
If it is really required to add the ListView or some such RepeatingView
to the RadioGroup, it also express the other problem that if there are
multiple radio groups say different fields in the rows, in which only
one selection is valid for each field cannot be implemented. Because
only a single ListView can be added to the RadioGroup, I'm not sure how
to add the same ListView to 2 different RadioGroups.
I'm not sure how to go about handling such needs.
I think I need to rework my design.
The use case is that there are multiple images in which they are listed
in a listview, so that the user can select a particular image to delete,
or set as the primary display image.
But it seemed difficult to implement such a page / form.
On 31/07/2025 22:15, andrew goh wrote:
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?