Add IChoiceRenderer to RadioGroup CheckGroup
--------------------------------------------

                 Key: WICKET-1644
                 URL: https://issues.apache.org/jira/browse/WICKET-1644
             Project: Wicket
          Issue Type: Improvement
          Components: wicket
    Affects Versions: 1.3.3
         Environment: N/A
            Reporter: Will Hoover
            Priority: Minor


Other components (i.e. DropDownChoice, CheckBoxMultipleChoice, etc.) that deal 
with choices have the ability to use an IChoiceRenderer in order to implement 
getDisplayValue(...) and getIdValue(...)
It is sometimes a requirement  to supply the ID value when making a selection 
using RadioGroup/CheckGroup. For example:

class MyObject {
        private Long id;
        private MyObjectOption myObjectOption;

        public MyObject(final Long id){
                setId(id);
                ...
        }
        ...
}

class MyObjectOption {
        private Long id;
        private String name;

        public MyObjectOption(final Long id){
                setId(id);
                ...
        }
        ...
}

// in the WebPage
final MyObject myObject = new MyObject(1L);
...
myObject.setMyObjectOption(new MyObjectOption(200L));

final List<MyObjectOption> myObjectOptionList = new
ArrayList<MyObjectOption>();
myObjectOptionList.add(new MyObjectOption(100L));
myObjectOptionList.add(new MyObjectOption(200L));
myObjectOptionList.add(new MyObjectOption(300L));

final Form myForm = new Form("form-myobject", new
CompoundPropertyModel(myObject));
...
final RadioGroup group = new RadioGroup("myObjectOption");
group.add(new ListView("div-myobject-options-view", myObjectList) {
        protected final void populateItem(final ListItem item) {
                final MyObjectOption myObjectOption = (MyObjectOption)
item.getModelObject();
                item.add(new Label("label-myobject-option-name",
myObjectOption.getName()));
                item.add(new Radio("input-radio-myobject-option", new
Model(myObjectOption)));
        }
});
myForm.add(group);
add(myForm);


<form wicket:id="form-myobject">
        <div wicket:id="myObjectOption">
                <div wicket:id="div-myobject-options-view">
                        <label wicket:id="label-myobject-option-name">
                                [MyObjectOption Name]
                        </label>
                        <input wicket:id="input-radio-myobject-option"
type="radio" />
                </div>
        </div>
</form>

In the example above myObjectOption would never be selected because it
is not the same instance of the MyObjectOption that is in
myObjectOptionList (index 1) even though they share the same ID. If an
IChoiceRenderer was provided to the RadioGroup the following could
accomplish the task of making the selection work:

final IChoiceRenderer myObjectOptionRenderer = new ChoiceRenderer() {
        ...
        public final String getIdValue(final Object object, final int
index) {
                final Object id = ((MyObjectOption) object).getId();
                return (id != null) ? id.toString() :
super.getIdValue(object, index);
        }
        ...
};

An easy solution to the above example is to ensure that equals and hashcode are 
overridden, but if MyObject and MyObjectOption are not within the developers 
namespace then this will not be possible. Also, for consistency sake, if other 
components that deal with choices have the capability to use an IChoiceRenderer 
then RadioGroup/CheckGroup should also have that option.

Full forum thread: http://www.mail-archive.com/[EMAIL PROTECTED]/msg18283.html

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to