You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Igor Vaynberg (JIRA)" <ji...@apache.org> on 2011/09/18 02:29:09 UTC

[jira] [Resolved] (WICKET-1644) Add IChoiceRenderer to RadioGroup CheckGroup

     [ https://issues.apache.org/jira/browse/WICKET-1644?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-1644.
-----------------------------------

    Resolution: Won't Fix

the same problem happens with ichoicerenderer, the id objects must implement equals and hashcode.

the other components use renderers because they are not meant to allow the user to tweak the markup, which group components do.

if the objects are outside of developers scope then wrap them with objects that are in your scope and that implement proper hashcode/equals.

> 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
>            Assignee: Igor Vaynberg
>            Priority: Minor
>   Original Estimate: 168h
>  Remaining Estimate: 168h
>
> 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/users@wicket.apache.org/msg18283.html

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira