This is a full functional Page  :

I found this problem only occurs when the form is in the listView :
If I move the form out of the listView , it works like a charm.
Bug ? I am not sure...

The link is the screen capture :
http://xs.to/image-B859_4B57CDD0.gif


MyPage.html

<table border="1">
  <tr>
    <th>name</th>
    <th>more ?</th>
  </tr>
  <span wicket:id="listView">
    <form wicket:id="form">
      <tr>
        <td wicket:id="name">[name]</td>
        <td>
          <span wicket:id="radioGroup">
            <input type="radio" wicket:id="yes"/>yes
            <input type="radio" wicket:id="no"/>no
          </span>
        </td>
      </tr>
      <tr wicket:id="more">
        <td colspan="2">
          <input type="text" size="40" value="Please leave comments"
wicket:id="textfield"/>
          <input type="submit" value="Submit" wicket:id="submit"/>
        </td>
      </tr>
    </form>
  </span>
</table>


MyPage.java

package quickstart.ajax;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.Radio;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;

public class MyPage extends WebPage
{
  private final static List<String> names = new ArrayList<String>();
  static
  {
    names.add("Andy");
    names.add("Brian");
    names.add("Carol");
  }

  public MyPage()
  {
    ListView<String> listView = new ListView<String>("listView" , names)
    {
      @Override
      protected void populateItem(ListItem<String> item)
      {

        Form<Void> form = new Form<Void>("form");
        item.add(form);

        String name = item.getModelObject();

        form.add(new Label("name" , name));

        final WebMarkupContainer more = new WebMarkupContainer("more");
        more.setVisible(false);
        more.setOutputMarkupPlaceholderTag(true);
        form.add(more);


        final RadioGroup<Boolean> radioGroup = new
RadioGroup<Boolean>("radioGroup" , Model.of(Boolean.FALSE));
        form.add(radioGroup);

        Radio<Boolean> yes = new Radio<Boolean>("yes" ,
Model.of(Boolean.TRUE));
        Radio<Boolean> no = new Radio<Boolean>("no" ,
Model.of(Boolean.FALSE));
        radioGroup.add(yes);
        radioGroup.add(no);

        yes.add(new AjaxEventBehavior("onClick")
        {
          @Override
          protected void onEvent(AjaxRequestTarget target)
          {
            more.setVisible(true);
            target.addComponent(more);
          }
        });

        no.add(new AjaxEventBehavior("onClick")
        {
          @Override
          protected void onEvent(AjaxRequestTarget target)
          {
            more.setVisible(false);
            target.addComponent(more);
          }
        });

        final TextField<String> textfield = new
TextField<String>("textfield" , new Model<String>());
        more.add(textfield);
        AjaxButton button = new AjaxButton("submit")
        {
          @Override
          protected void onSubmit(AjaxRequestTarget arg0, Form<?> form)
          {
            System.out.println("radioGroup = " + radioGroup.getModelObject()
+ " , textfield.getModelObject() = " + textfield.getModelObject());
          }
        };
        more.add(button);
      }
    };
    add(listView);
  }
}

Reply via email to