Hi All,
I have a two Radios that control two dropdowns which get Enabled/disbaled
based on radio selected. All the four components are a part of radiogroup. 
When page is loaded radio1 is pre-selected and Dropdown1 is enabled--radio2
is unselected and DropDown2 is dis-abled.

The Problem:
When I change the selection and select radio2 (which enables DropDown2 also,
and subsequently disables Dropdown1 and unselects radio1) and submit the
form I get the Exception
Attempted to set property value on a null object. Property expression: ddc2
Value: codeA21/descA21

I believe when second radio button is selected the model somehow becomes
null. 
No matter where I put the code for the model  I cannot get past the
exception mentioned above.

I tried putting it in AjaxEventBehavior attached to radios and in
AjaxFormChoiceComponentUpdatingBehavior attached to radiogroup but no help.

Question:
1. Where should the code for enable/disable dropdowns should go
"AjaxEventBehavior" attached to radios or
"AjaxFormChoiceComponentUpdatingBehavior"
   attached to radiogroup?
2. How should I update the model behind then dropdown? I set the model when
I load up the form but this doesn't seem to work.
3. After changing the radio selection When I submit the form the form model
also becomes null, why is that?

Please point out what am I missing.

Here is my current code snippet looks like.
Wicket 1.3.4
java 1.5

=============
TestForm.java
=============
    private class TestForm extends Form 
    {

        private DropDownChoice ddc1;
        private DropDownChoice ddc2;

        public TestForm(String id) {
            super(id);
            IModel formModel = new CompoundPropertyModel(new Person());
            setModel(formModel);

            final RadioGroup group = new RadioGroup("group", formModel);

            Radio radio1 = new Radio("radio1", formModel);
            Radio radio2 = new Radio("radio2", formModel);

            // DropDown controlled by Radio1...     
            DDCPOJO pojo1 = new DDCPOJO("codeA11", "descA11");
            DDCPOJO pojo2 = new DDCPOJO("codeA12", "descA12");
            DDCPOJO pojo3 = new DDCPOJO("codeA13", "descA13");
            final List<DDCPOJO> alPojo1 = new ArrayList<DDCPOJO>();
            alPojo1.add(pojo1);
            alPojo1.add(pojo2);
            alPojo1.add(pojo3);

            ddc1 = new DropDownChoice("ddc1", alPojo1, new ChoiceRenderer(
                    "code", "code"));
            ddc1.setOutputMarkupId(true);

            // Second DDC....  
            DDCPOJO pojo4 = new DDCPOJO("codeA21", "descA21");
            DDCPOJO pojo5 = new DDCPOJO("codeA22", "descA22");
            DDCPOJO pojo6 = new DDCPOJO("codeA23", "descA23");
            final List<DDCPOJO> alPojo2 = new ArrayList<DDCPOJO>();
            alPojo2.add(pojo4);
            alPojo2.add(pojo5);
            alPojo2.add(pojo6);

            ddc2 = new DropDownChoice("ddc2", alPojo2, new ChoiceRenderer(
                    "code", "code"));
            ddc2.setOutputMarkupId(true);

            radio1.add(new AjaxEventBehavior("onClick") {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    group.processInput();
                    // On click DISABLE text2 and ddc2
                    ddc2.setEnabled(false);

                    // On click ENABLE text1 and ddc1
                    ddc1.setEnabled(true);
                    // Add the targets.             
                    target.addComponent(ddc2);
                    target.addComponent(ddc1);
                }

            });

            radio2.add(new AjaxEventBehavior("onClick") {
                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {

                    group.processInput();
                    // On click DISABLE text1 and ddc1
                    ddc1.setEnabled(false);
                    // On click ENABLE text2 and ddc2               
                    ddc2.setEnabled(true);
                    // Add the Targets...
                    target.addComponent(ddc2);
                    target.addComponent(ddc1);

                }

            });

            // Add the Radio to Group
            group.add(radio1);
            group.add(radio2);

            // Add the drop down choice to group
            group.add(ddc1);
            group.add(ddc2);

            add(group);

            group.add(new AjaxFormChoiceComponentUpdatingBehavior() {
                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    if (group.getInput().equals("radio1")) 
                    {
                        // I am doing that in "AjaxEventBehavior also
                        // Don't know what is the correct place to do it.
                        
                        // On click DISABLE text2 and ddc2
                        ddc2.setEnabled(false);

                        // On click ENABLE text1 and ddc1
                        ddc1.setEnabled(true);
                        // Add the targets.                 
                        target.addComponent(ddc2);
                        target.addComponent(ddc1);

                    } else {
                        // On click DISABLE text1 and ddc1
                        ddc1.setEnabled(false);
                        // On click ENABLE text2 and ddc2                   
                        ddc2.setEnabled(true);
                        // Add the Targets...
                        target.addComponent(ddc2);
                        target.addComponent(ddc1);
                    }
                }

            });

            add(new AjaxFallbackButton("btnSubmit", formModel, 
this.getRootForm())
{
                @Override
                protected void onSubmit(AjaxRequestTarget target, Form form) 
                {
                    Person p = (Person) form.getModelObject();
                    System.out.println(p.toString());

                }

            });

        }
    }

=============
TestForm.html
=============
        <form wicket:id="testForm">
        <div wicket:id="group">
                <table>
                        <tr>
                                <td>
                                         <label>Radio 1</label> 
                                         <input type="radio" wicket:id="radio1" 
/> 
                                 </td>
                                <td>
                                        <select wicket:id="ddc1">
                                <option>ddc11</option>
                                <option>ddc12</option>
                            </select>
                    </td>
                        </tr>
                        <tr>
                          <td>
                              <label>Radio 2</label>
                                          <input type="radio" 
wicket:id="radio2" />
                         </td>
                          <td>
                                  <select wicket:id="ddc2">
                                                <option>ddc21</option>
                                                <option>ddc22</option>
                                  </select>
                          </td>
                        </tr>
                </table>
        </div> 
        <input type="submit" wicket:id="btnSubmit" value="Submit Form" /></form>

-- 
View this message in context: 
http://www.nabble.com/Need-little-help-in-understanding-AjaxEventBehavior%28on-a-Radio%29-and-AjaxFormChoiceComponentUpdatingBehavior%28on-a-RadioGroup%29-tp18824832p18824832.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to