Re: RadioChoice showing last choosen value - what am i doing wrong
Hi Igor, The code did not work with even though the component was enabled. The equals and hashcode methods are implemented for the LabelValue. But instead of using my own Model implementation and managing the dynamic behaviour, i added a PropertyModel to the RadioChoice, and now it works perfectly. Here is the code, if someone should be interested: public class QuestionPanel extends Panel { private LabelValue selectedValue; radioChoice = new RadioChoice(radioChoice, new PropertyModel(this, selectedValue), yesNoList, new ChoiceRenderer(label, value)).setSuffix(); ... selectedValue = getPreviouslyChoosenLabelValue(); ... } Thanks for the response Igor... Best Regards Muro On Mon, Oct 12, 2009 at 5:06 PM, Igor Vaynberg igor.vaynb...@gmail.comwrote: does that code work if the component is not disabled? does LabelValue have equals/hashcode properly implemented so the one you push with setmodelobject will match one in the yesNoChoices collection? -igor On Mon, Oct 12, 2009 at 6:40 AM, Muro Copenhagen copenha...@gmail.com wrote: Hi, Any help on this issue regarding the RadioChoice component will be appreciated. I'm having difficiltius showing the (previously) selected RadioChoice, and can not figure out what's going wrong. Here is my code: public class QuestionRightPanel extends Panel { private String selectedValue; private RadioChoice radioChoice; ... public QuestionRightPanel() { ... radioChoice = new RadioChoice(radioChoice, new MyModel(), yesNoChoices, new ChoiceRenderer(label, value)).setSuffix(); ... selectedValue = getAlreadyChoosenValue(); if (questionAnswered) { radioChoice.setVisible(true); radioChoice.setEnabled(false); radioChoice.setModelObject(new LabelValue(convertYesNo(selectedValue), selectedValue)); } class MyModel extends Model { @Override public Object getObject() { return selectedValue; } @Override public void setObject(Serializable object) { if (object != null) { // set the yes-no value choosen. selectedValue = ((LabelValue) object).getValue(); } } } As seen i don't want the user to answer the question again by disabling the radioChoice if the question already has been answered. By why can't i set the default selected option to be the value i desire by the code: radioChoice.setModelObject(new LabelValue(convertYesNo(selectedValue), selectedValue)); Hope someone has the answer... Best Regards Muro - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RadioChoice showing last choosen value - what am i doing wrong
Hi, Any help on this issue regarding the RadioChoice component will be appreciated. I'm having difficiltius showing the (previously) selected RadioChoice, and can not figure out what's going wrong. Here is my code: public class QuestionRightPanel extends Panel { private String selectedValue; private RadioChoice radioChoice; ... public QuestionRightPanel() { ... radioChoice = new RadioChoice(radioChoice, new MyModel(), yesNoChoices, new ChoiceRenderer(label, value)).setSuffix(); ... selectedValue = getAlreadyChoosenValue(); if (questionAnswered) { radioChoice.setVisible(true); radioChoice.setEnabled(false); radioChoice.setModelObject(new LabelValue(convertYesNo(selectedValue), selectedValue)); } class MyModel extends Model { @Override public Object getObject() { return selectedValue; } @Override public void setObject(Serializable object) { if (object != null) { // set the yes-no value choosen. selectedValue = ((LabelValue) object).getValue(); } } } As seen i don't want the user to answer the question again by disabling the radioChoice if the question already has been answered. By why can't i set the default selected option to be the value i desire by the code: radioChoice.setModelObject(new LabelValue(convertYesNo(selectedValue), selectedValue)); Hope someone has the answer... Best Regards Muro
Re: RadioChoice showing last choosen value - what am i doing wrong
does that code work if the component is not disabled? does LabelValue have equals/hashcode properly implemented so the one you push with setmodelobject will match one in the yesNoChoices collection? -igor On Mon, Oct 12, 2009 at 6:40 AM, Muro Copenhagen copenha...@gmail.com wrote: Hi, Any help on this issue regarding the RadioChoice component will be appreciated. I'm having difficiltius showing the (previously) selected RadioChoice, and can not figure out what's going wrong. Here is my code: public class QuestionRightPanel extends Panel { private String selectedValue; private RadioChoice radioChoice; ... public QuestionRightPanel() { ... radioChoice = new RadioChoice(radioChoice, new MyModel(), yesNoChoices, new ChoiceRenderer(label, value)).setSuffix(); ... selectedValue = getAlreadyChoosenValue(); if (questionAnswered) { radioChoice.setVisible(true); radioChoice.setEnabled(false); radioChoice.setModelObject(new LabelValue(convertYesNo(selectedValue), selectedValue)); } class MyModel extends Model { �...@override public Object getObject() { return selectedValue; } �...@override public void setObject(Serializable object) { if (object != null) { // set the yes-no value choosen. selectedValue = ((LabelValue) object).getValue(); } } } As seen i don't want the user to answer the question again by disabling the radioChoice if the question already has been answered. By why can't i set the default selected option to be the value i desire by the code: radioChoice.setModelObject(new LabelValue(convertYesNo(selectedValue), selectedValue)); Hope someone has the answer... Best Regards Muro - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org