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() {            
              Form<Void> form = new Form<Void>("form");
              add(form);        
              context = new WebMarkupContainer("context");
              context.setOutputMarkupId(true);
              form.add(context);

                
                RadioGroup<Gender> gender = new RadioGroup<Gender>("gender",
                                new PropertyModel<Gender>(this,"gender"));
                
                gender.setRequired(true);
                context.add(gender);
                // hombre
                Radio<Gender> sexoH = new Radio<Gender>("male", new
Model<Gender>(Gender.MALE), gender);
                gender.add(sexoH);
                
                Radio<Gender> sexoM = new Radio<Gender>("female", new
Model<Gender>(Gender.FEMALE), gender);
                gender.add(sexoM);
                
                add(new AjaxLink<Void>("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 AjaxLink<Void>("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>
        <title>Test</title>
    </head>
    <body>
        <form wicket:id="form">
                <div wicket:id="context">
                        <span wicket:id="gender">
                                        <input type="radio" wicket:id="male"/>
                                        <label for="radio3">Male</label>
                                        <input type="radio" wicket:id="female"/>
                                        <label for="radio4">Female</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="makeMale">Make male</a> and <a
wicket:id="makeFemale">Make 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 model objects of the group and self, if
the same add the
                // checked attribute, first check if there was a raw input on 
the group.
                if (group.hasRawInput())
                {
                        String rawInput = group.getRawInput();
                        if (rawInput != null && rawInput.equals(value))
                        {
                                tag.put("checked", "checked");
                        }
                }

If I rewrite my gender RadioGroup as

RadioGroup<Gender> gender = new RadioGroup<Gender>("gender",
                                new PropertyModel<Gender>(this,"gender")) {
                
                        private static final long serialVersionUID = 1L;
        
                        @Override
                        public boolean isInputNullable() {
                                return false;
                        }
                };

"everything" seems to be working fine. Am I missing some important
point on how to use radio groups or  is this a bug? Shall I file a
jira issue for this?

Thanks in advance,

Ernesto

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to