Re: radio group stated not updated via AJAX. Possible bug?

2010-12-30 Thread Ernesto Reinaldo Barreiro
I forgot to mentions this is with wicket 1.4.x.

Ernesto

On Thu, Dec 30, 2010 at 1:53 PM, Ernesto Reinaldo Barreiro
reier...@gmail.com wrote:
 Hi,

 Apologies for the somewhat lengthy e-mail.

 Consider the following situation

 1-I have a form with a RadioGroup, several Radio buttons, an AJAX
 submit button and some AJAX links that fetch information that can be
 used to repaint the form and the RadioGroup.

 In simplified code more or less this.

 public class RadioPage extends WebPage  {

        private static final long serialVersionUID = 1L;

        private WebMarkupContainer context;

        private Gender gender;

        private FeedbackPanel feedbackPanel;

        public RadioPage() {
              FormVoid form = new FormVoid(form);
              add(form);
              context = new WebMarkupContainer(context);
              context.setOutputMarkupId(true);
              form.add(context);


                RadioGroupGender gender = new RadioGroupGender(gender,
                                new PropertyModelGender(this,gender));

                gender.setRequired(true);
                context.add(gender);
                // hombre
                RadioGender sexoH = new RadioGender(male, new
 ModelGender(Gender.MALE), gender);
                gender.add(sexoH);

                RadioGender sexoM = new RadioGender(female, new
 ModelGender(Gender.FEMALE), gender);
                gender.add(sexoM);

                add(new AjaxLinkVoid(makeMale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.MALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                add(new AjaxLinkVoid(makeFemale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.FEMALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                form.add(new AjaxSubmitLink(submit) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        protected void onSubmit(AjaxRequestTarget target, 
 Form? form) {
                                form.info(Gender was set to  + 
 RadioPage.this.gender);
                                target.addComponent(feedbackPanel);
                        }

                       �...@override
                        protected void onError(AjaxRequestTarget target, 
 Form? form) {
                                target.addComponent(feedbackPanel);
                        }
                });

                feedbackPanel = new FeedbackPanel(feedback);
                feedbackPanel.setOutputMarkupId(true);
                add(feedbackPanel);
    }

        public Gender getGender() {
                return gender;
        }

        public void setGender(Gender gender) {
                this.gender = gender;
        }
 }

 -RadioPage.html--

 html 
 xmlns:wicket=http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd;
    head
        titleTest/title
    /head
    body
        form wicket:id=form
                div wicket:id=context
                        span wicket:id=gender
                                        input type=radio wicket:id=male/
                                        label for=radio3Male/label
                                        input type=radio 
 wicket:id=female/
                                        label for=radio4Female/label
                                /span
                        /div
                        input wicket:id=submit type=submit value=AJAX 
 submit/
                /form
                span wicket:id=feedback/span
                p
                        Updating RadioGroup via AJAX does not work:
                        a wicket:id=makeMaleMake male/a and a
 wicket:id=makeFemaleMake female/a.
                /p
    /body
 /html

 and

 public enum Gender {
        FEMALE,
        MALE;
 }


 2-You click on the AJAX submit button without selecting any of the
 radio buttons. This seems to set the rawinput of  RadioGroup to null.
 3-You click now on one of the AJAX links (Make male or Make female in
 the example) in order to fetch the information  and repaint the form
 via AJAX. But radios checked condition is not updated:-(

 This seems to be because of following code on Radio.onComponentTag():

                // compare the 

Re: radio group stated not updated via AJAX. Possible bug?

2010-12-30 Thread Igor Vaynberg
call clearinput() on the radiogroup so it refreshes based on new model
value you set.

-igor

On Thu, Dec 30, 2010 at 4:57 AM, Ernesto Reinaldo Barreiro
reier...@gmail.com wrote:
 I forgot to mentions this is with wicket 1.4.x.

 Ernesto

 On Thu, Dec 30, 2010 at 1:53 PM, Ernesto Reinaldo Barreiro
 reier...@gmail.com wrote:
 Hi,

 Apologies for the somewhat lengthy e-mail.

 Consider the following situation

 1-I have a form with a RadioGroup, several Radio buttons, an AJAX
 submit button and some AJAX links that fetch information that can be
 used to repaint the form and the RadioGroup.

 In simplified code more or less this.

 public class RadioPage extends WebPage  {

        private static final long serialVersionUID = 1L;

        private WebMarkupContainer context;

        private Gender gender;

        private FeedbackPanel feedbackPanel;

        public RadioPage() {
              FormVoid form = new FormVoid(form);
              add(form);
              context = new WebMarkupContainer(context);
              context.setOutputMarkupId(true);
              form.add(context);


                RadioGroupGender gender = new RadioGroupGender(gender,
                                new PropertyModelGender(this,gender));

                gender.setRequired(true);
                context.add(gender);
                // hombre
                RadioGender sexoH = new RadioGender(male, new
 ModelGender(Gender.MALE), gender);
                gender.add(sexoH);

                RadioGender sexoM = new RadioGender(female, new
 ModelGender(Gender.FEMALE), gender);
                gender.add(sexoM);

                add(new AjaxLinkVoid(makeMale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.MALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                add(new AjaxLinkVoid(makeFemale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.FEMALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                form.add(new AjaxSubmitLink(submit) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        protected void onSubmit(AjaxRequestTarget target, 
 Form? form) {
                                form.info(Gender was set to  + 
 RadioPage.this.gender);
                                target.addComponent(feedbackPanel);
                        }

                       �...@override
                        protected void onError(AjaxRequestTarget target, 
 Form? form) {
                                target.addComponent(feedbackPanel);
                        }
                });

                feedbackPanel = new FeedbackPanel(feedback);
                feedbackPanel.setOutputMarkupId(true);
                add(feedbackPanel);
    }

        public Gender getGender() {
                return gender;
        }

        public void setGender(Gender gender) {
                this.gender = gender;
        }
 }

 -RadioPage.html--

 html 
 xmlns:wicket=http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd;
    head
        titleTest/title
    /head
    body
        form wicket:id=form
                div wicket:id=context
                        span wicket:id=gender
                                        input type=radio wicket:id=male/
                                        label for=radio3Male/label
                                        input type=radio 
 wicket:id=female/
                                        label for=radio4Female/label
                                /span
                        /div
                        input wicket:id=submit type=submit value=AJAX 
 submit/
                /form
                span wicket:id=feedback/span
                p
                        Updating RadioGroup via AJAX does not work:
                        a wicket:id=makeMaleMake male/a and a
 wicket:id=makeFemaleMake female/a.
                /p
    /body
 /html

 and

 public enum Gender {
        FEMALE,
        MALE;
 }


 2-You click on the AJAX submit button without selecting any of the
 radio buttons. This seems to set the rawinput of  RadioGroup to null.
 3-You click now on one of the AJAX links (Make male or Make female in
 the example) in order to fetch the information  

Re: radio group stated not updated via AJAX. Possible bug?

2010-12-30 Thread Ernesto Reinaldo Barreiro
Igor,

Thanks for your answer. Yes, I thought about that possibility but
somehow it seems weird to me that you have to call clearinput() to get
the component update its state based on the model value: in particular
because other form components do not need that trick to work properly.
 Would the override

 public boolean isInputNullable() {
return false;
 }

have any other (undesirable) side effects? This solution has the
advantage that I can roll out my own AjaxUpdatebleRadioGroup and thus
I do not have remember to call clearinput() over and over.

Regards,

Ernesto

On Thu, Dec 30, 2010 at 3:29 PM, Igor Vaynberg igor.vaynb...@gmail.com wrote:
 call clearinput() on the radiogroup so it refreshes based on new model
 value you set.

 -igor

 On Thu, Dec 30, 2010 at 4:57 AM, Ernesto Reinaldo Barreiro
 reier...@gmail.com wrote:
 I forgot to mentions this is with wicket 1.4.x.

 Ernesto

 On Thu, Dec 30, 2010 at 1:53 PM, Ernesto Reinaldo Barreiro
 reier...@gmail.com wrote:
 Hi,

 Apologies for the somewhat lengthy e-mail.

 Consider the following situation

 1-I have a form with a RadioGroup, several Radio buttons, an AJAX
 submit button and some AJAX links that fetch information that can be
 used to repaint the form and the RadioGroup.

 In simplified code more or less this.

 public class RadioPage extends WebPage  {

        private static final long serialVersionUID = 1L;

        private WebMarkupContainer context;

        private Gender gender;

        private FeedbackPanel feedbackPanel;

        public RadioPage() {
              FormVoid form = new FormVoid(form);
              add(form);
              context = new WebMarkupContainer(context);
              context.setOutputMarkupId(true);
              form.add(context);


                RadioGroupGender gender = new RadioGroupGender(gender,
                                new PropertyModelGender(this,gender));

                gender.setRequired(true);
                context.add(gender);
                // hombre
                RadioGender sexoH = new RadioGender(male, new
 ModelGender(Gender.MALE), gender);
                gender.add(sexoH);

                RadioGender sexoM = new RadioGender(female, new
 ModelGender(Gender.FEMALE), gender);
                gender.add(sexoM);

                add(new AjaxLinkVoid(makeMale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.MALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                add(new AjaxLinkVoid(makeFemale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.FEMALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                form.add(new AjaxSubmitLink(submit) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        protected void onSubmit(AjaxRequestTarget target, 
 Form? form) {
                                form.info(Gender was set to  + 
 RadioPage.this.gender);
                                target.addComponent(feedbackPanel);
                        }

                       �...@override
                        protected void onError(AjaxRequestTarget target, 
 Form? form) {
                                target.addComponent(feedbackPanel);
                        }
                });

                feedbackPanel = new FeedbackPanel(feedback);
                feedbackPanel.setOutputMarkupId(true);
                add(feedbackPanel);
    }

        public Gender getGender() {
                return gender;
        }

        public void setGender(Gender gender) {
                this.gender = gender;
        }
 }

 -RadioPage.html--

 html 
 xmlns:wicket=http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd;
    head
        titleTest/title
    /head
    body
        form wicket:id=form
                div wicket:id=context
                        span wicket:id=gender
                                        input type=radio 
 wicket:id=male/
                                        label for=radio3Male/label
                                        input type=radio 
 wicket:id=female/
                                        label for=radio4Female/label
                                /span
                        /div
                        

Re: radio group stated not updated via AJAX. Possible bug?

2010-12-30 Thread Igor Vaynberg
all components need that after they have been submitted once. how is
component to know that you have updated its model object? have you
called component.modelchanged()? clearinput() will do the same as
that.

-igor

On Thu, Dec 30, 2010 at 6:46 AM, Ernesto Reinaldo Barreiro
reier...@gmail.com wrote:
 Igor,

 Thanks for your answer. Yes, I thought about that possibility but
 somehow it seems weird to me that you have to call clearinput() to get
 the component update its state based on the model value: in particular
 because other form components do not need that trick to work properly.
  Would the override

  public boolean isInputNullable() {
        return false;
  }

 have any other (undesirable) side effects? This solution has the
 advantage that I can roll out my own AjaxUpdatebleRadioGroup and thus
 I do not have remember to call clearinput() over and over.

 Regards,

 Ernesto

 On Thu, Dec 30, 2010 at 3:29 PM, Igor Vaynberg igor.vaynb...@gmail.com 
 wrote:
 call clearinput() on the radiogroup so it refreshes based on new model
 value you set.

 -igor

 On Thu, Dec 30, 2010 at 4:57 AM, Ernesto Reinaldo Barreiro
 reier...@gmail.com wrote:
 I forgot to mentions this is with wicket 1.4.x.

 Ernesto

 On Thu, Dec 30, 2010 at 1:53 PM, Ernesto Reinaldo Barreiro
 reier...@gmail.com wrote:
 Hi,

 Apologies for the somewhat lengthy e-mail.

 Consider the following situation

 1-I have a form with a RadioGroup, several Radio buttons, an AJAX
 submit button and some AJAX links that fetch information that can be
 used to repaint the form and the RadioGroup.

 In simplified code more or less this.

 public class RadioPage extends WebPage  {

        private static final long serialVersionUID = 1L;

        private WebMarkupContainer context;

        private Gender gender;

        private FeedbackPanel feedbackPanel;

        public RadioPage() {
              FormVoid form = new FormVoid(form);
              add(form);
              context = new WebMarkupContainer(context);
              context.setOutputMarkupId(true);
              form.add(context);


                RadioGroupGender gender = new RadioGroupGender(gender,
                                new PropertyModelGender(this,gender));

                gender.setRequired(true);
                context.add(gender);
                // hombre
                RadioGender sexoH = new RadioGender(male, new
 ModelGender(Gender.MALE), gender);
                gender.add(sexoH);

                RadioGender sexoM = new RadioGender(female, new
 ModelGender(Gender.FEMALE), gender);
                gender.add(sexoM);

                add(new AjaxLinkVoid(makeMale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.MALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                add(new AjaxLinkVoid(makeFemale) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        public void onClick(AjaxRequestTarget target) {
                                RadioPage.this.gender = Gender.FEMALE;
                                if(target != null) {
                                        target.addComponent(context);
                                }
                        }
                });

                form.add(new AjaxSubmitLink(submit) {

                        private static final long serialVersionUID = 1L;

                       �...@override
                        protected void onSubmit(AjaxRequestTarget target, 
 Form? form) {
                                form.info(Gender was set to  + 
 RadioPage.this.gender);
                                target.addComponent(feedbackPanel);
                        }

                       �...@override
                        protected void onError(AjaxRequestTarget target, 
 Form? form) {
                                target.addComponent(feedbackPanel);
                        }
                });

                feedbackPanel = new FeedbackPanel(feedback);
                feedbackPanel.setOutputMarkupId(true);
                add(feedbackPanel);
    }

        public Gender getGender() {
                return gender;
        }

        public void setGender(Gender gender) {
                this.gender = gender;
        }
 }

 -RadioPage.html--

 html 
 xmlns:wicket=http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd;
    head
        titleTest/title
    /head
    body
        form wicket:id=form
                div wicket:id=context
                        span wicket:id=gender
                                        input type=radio