[
https://issues.apache.org/jira/browse/WICKET-5255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13695065#comment-13695065
]
Ronald Tetsuo Miura commented on WICKET-5255:
---------------------------------------------
You can pass the CheckGroup in the Check constructor, but Check still needs to
be inside CheckGroup (somewhere in ints hierarchy). It's there so that, if you
have two or more groups interleaved (like, two columns of checkboxes in a
table), you can specify to which group a Check refers, but you still have to
wrap everything with the group(s).
>From the javadoc:
"Instances of Check have to be in the component hierarchy somewhere below the
group component."
But this is only because CheckGroup.convertValue() looks for Checks visiting
only its own children. If it's changed to search its form children, it seems to
work (I did a quick test):
{code}
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
public HomePage(final PageParameters parameters) {
super(parameters);
final CheckGroup<String> group = new CheckGroup<String>("group", new
ArrayList<String>(Arrays.asList("A"))) {
// I copied the original convertValue() code, and just added the
getForm()
@Override
protected Collection<String> convertValue(String[] values) throws
ConversionException
{
List<String> collection = Generics.newArrayList();
/*
* if the input is null we do not need to do anything since the
model collection has already
* been cleared
*/
if (values != null && values.length > 0)
{
for (final String value : values)
{
if (value != null)
{
Check<String> checkbox =
getForm().visitChildren(Check.class, // ############
added getForm().
new
org.apache.wicket.util.visit.IVisitor<Check<String>, Check<String>>()
{
@Override
public void component(final Check<String>
check, final IVisit<Check<String>> visit)
{
if
(String.valueOf(check.getValue()).equals(value))
{
visit.stop(check);
}
}
});
if (checkbox == null)
{
throw new WicketRuntimeException(
"submitted http post value [" +
Strings.join(",", values) +
"] for CheckGroup component [" +
getPath() +
"] contains an illegal value [" +
value +
"] which does not point to a Check
component. Due to this the CheckGroup component cannot resolve the selected
Check component pointed to by the illegal value. A possible reason is that
component hierarchy changed between rendering and form submission.");
}
// assign the value of the group's model
collection.add(checkbox.getModelObject());
}
}
}
return collection;
}
};
add(new Form<Void>("form") {
protected void onSubmit() {
System.out.println(group.getModelObject());
}
}
.add(group)
.add(new Check<String>("a", Model.of("A"), group))
.add(new Check<String>("b", Model.of("B"), group))
.add(new Check<String>("c", Model.of("C"), group)));
}
}
{code}
> Make RadioGroup and CheckGroup non-components
> ---------------------------------------------
>
> Key: WICKET-5255
> URL: https://issues.apache.org/jira/browse/WICKET-5255
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 7.0.0
> Reporter: Martin Grigorov
> Fix For: 7.0.0
>
>
> Description of the task by Igor Vaynberg:
> the basic idea is to make
> CheckGroup and RadioGroup non-components because in a lot of cases it
> is inconvenient to have them wrap some sections. eg when you have two
> check groups you have to put one inside the other, which is
> non-intuitive. so the groups are linked by the instance of CheckGroup
> and RadioGroup objects which can take care of generating unique ids,
> etc.
> so instead of code like this:
> RadioGroup group=new RadioGroup();
> add(group);
> group.add(new Radio());
> we would have
> RadioGroup group=new RadioGroup();
> add(new Radio("id", group));
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira