I completed a Wicket 1.2 project a couple of years ago, and I've been
maintaining it since then. I've been using Version 1.2.2 successfully,
and figured I might as well use the lastest release of that version
(1.2.7). Well, I'm trying to figure out why Wicket 1.2.7 broke my code.
(I scrounged up a Wicket 1.2.6 release, and that also breaks it.)

Am I using the Wicket 1.2 API incorrectly?  When it works in Wicket
1.2.2, am I using it in an unintended way?  Let me illustrate what I've
been doing with a small example.

This is a simplified version of a component for creating and displaying
radio button groups without having to write HTML every time.  I give the
constructor:

(1) a wicket-id, 

(2) a PropertyModel that initializes the component and keeps track of
the current choice, and 

(3) an array of ChoiceOption.  -- The array of choice options defines
the set of values offered by the radio buttons, and the corresponding
labels to be displayed.

The component posts back immediately when a change is made to the radio
button.  (Think fast INTRAnet with a very small number of simulaneous
users.)  Here is my implementation:

package common.play;

import wicket.markup.html.basic.Label;
import wicket.model.IModel;
import wicket.markup.html.panel.Panel;
import wicket.markup.html.form.Radio;
import wicket.markup.html.form.RadioGroup;
import wicket.markup.html.list.ListItem;
import wicket.markup.html.list.ListView;
import wicket.model.PropertyModel;
import java.util.List;
import java.util.Arrays;
import common.play.ChoiceOption;

public class MyPanel extends Panel {

  public MyPanel( String id, String caption, PropertyModel groupModel,
ChoiceOption[] options) {
    super(id, groupModel);

    add( new Label("caption", caption) );
    final RadioGroup group = new RadioGroup("group", groupModel) {
      protected boolean wantOnSelectionChangedNotifications() { return
true; }
    };
    add(group);

    List<ChoiceOption> optionList = Arrays.asList( options );
    ListView radios = new ListView("radios", optionList) {
      protected void populateItem(ListItem listItem) {
        listItem.add( new Radio("radio",
                                new PropertyModel( listItem.getModel(),
"value") ) );
        listItem.add( new Label("option", new PropertyModel(
listItem.getModel(), "label" )));
      }
    };

    group.add(radios);
  }

----------------------------------------------------------------

package common.play;

public class ChoiceOption implements java.io.Serializable {
  public String value;
  public String label;

  public ChoiceOption(String value, String label) {
    this.value = value;
    this.label = label;
  }
}

------------------------------------------------------------------------
------------------------

This is the layout for displaying my component.  It's a divided box that
puts the group caption in one half, and in the other half provides the
set of labeled buttons.  Note that I'm using a ListView, because each
usage may require a different number of choices.

<html xmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>
" xmlns:wicket="http://wicket.sourceforge.net/
<http://wicket.sourceforge.net/> " xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<wicket:panel>
  <table border=1>
    <tr>
      <td>
        <span wicket:id="caption">Caption</span>
      </td>
      <td>
        <span wicket:id="group">
          <table cellpadding=5>
            <tr>
              <td wicket:id="radios" align="center">
                <input type="radio" wicket:id="radio"/>
                <span wicket:id="option">option name</span>
                &nbsp;
              </td>
            </tr>
          </table>
        </span>
      </td>
    </tr>
  </table>
</wicket:panel>
</body>
</html>


Here is a page with two intances of this component; one set of radio
buttons below the other, within a form.  Below my form are two labels,
one below the other, which indicate the value currently chosen by the
corresponding radio-button set. 

import wicket.markup.html.WebPage;
import wicket.markup.html.panel.Panel;
import wicket.markup.html.form.Form;
import wicket.model.PropertyModel;
import wicket.markup.html.basic.Label;
import common.play.ChoiceOption;

public class MyPage extends WebPage {

  public String firstProperty = "A";
  public String secondProperty = "A";

  ChoiceOption[] options = {   new ChoiceOption("A", "Ay"),
                               new ChoiceOption("B", "Bee"),
                               new ChoiceOption("C", "See"),
                               new ChoiceOption("D", "Dee") };

  public MyPage() {

      Form form = new Form("form");
      add( form );

      Panel panel1 = new MyPanel( "panel1",
                                  "1st choice",
                                  new PropertyModel( this,
"firstProperty"),
                                  options
                                );
      form.add( panel1 );


      Panel panel2 = new MyPanel( "panel2",
                                  "2nd choice",
                                  new PropertyModel( this,
"secondProperty"),
                                  options
                                );
      form.add( panel2 );

      add( new Label( "result1",
                      new PropertyModel(this, "firstProperty")
                    )
         );

      add( new Label( "result2",
                      new PropertyModel( this, "secondProperty")
                    )
         );
    }
}


<html xmlns="http://www.w3.org/1999/xhtml <http://www.w3.org/1999/xhtml>
" xmlns:wicket="http://wicket.sourceforge.net/
<http://wicket.sourceforge.net/> " xml:lang="en" lang="en">
<head>
  <link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<form wicket:id="form" id="form" name="form">
  <span wicket:id="panel1">  first radiobutton set appears here </span>
  <span wicket:id="panel2"> second radiobutton set appears here </span>
</form>
<div wicket:id="result1"> first selected choice appears here</div>
<div wicket:id="result2">second selected choice appears here</div>
</body>
</html>

 This works just fine in Wicket 1.2.2, but when I use Wicket 1.2.6 or
Wicket 1.2.7, I find that when I move the black dot by selecting another
choice in one group, the black dot in the other group disappears.
Sometimes both dots disappear.I play with the radio buttons the black
dot disappears, even though the model for each button group maintains
the proper value.

The disappearance of the indicator dot is merely the most obvious
manifestation of the problem.  By application is crashing like crazy
with Wicket 1.2.7, but works just fine with Wicket 1.2.2.

Am I using the Wicket 1.2 API incorrectly?  Is there some problem with
my use of ListView, or PropertyModel?  When it works in Wicket 1.2.2, am
I taking advantage of undocumented behavior?  What am I
misunderstanding?  If this is the result of a change that was made for
improved AJAX support, what would be my simplest work-around?

/Frank

 

Reply via email to