Igor Vaynberg wrote:
where is your Form in your example?

-igor

On Thu, Jul 16, 2009 at 7:04 AM, Trojahn,
Cassia<cassia.troj...@xrce.xerox.com> wrote:
Trojahn, Cassia wrote:
Always the last of the list is the selected.
I had tried also this proposal .. and it does not work.

Michael O'Cleirigh wrote:
Hello,

I don't think you need to track the selected (true/false) state your
self.  Let the radio group model do it automatically for you like:

listLanguages.add(new NameWrapper("English", "en", "");
listLanguages.add(new NameWrapper("German", "de", ""));
listLanguages.add(new NameWrapper("French", "fr", ""));
listLanguages.add(new NameWrapper("Italian", "it", "");
listLanguages.add(new NameWrapper("Polish", "pl", "");

// set the selected radio to be the first in the list 'English'
final RadioGroup groupQuery = new RadioGroup("groupLanguagesQuery", new
Model<NameWrapper>(listLanguages.get(0)));
listLanguagesQuery = new ListView("listLanguagesQuery",listLanguages) {
          protected void populateItem(ListItem item) {
               String lang =
((NameWrapper)item.getModelObject()).getName();
              item.add(new Label("nameLanguageQuery", new
StringResourceModel(lang, this, null,"XXXX")));
              item.add(new Radio("checkLanguageQuery",
item.getModel(),groupQuery));
          }
      };

groupQuery.add(listLanguagesQuery);

Now the model object value of the RadioGroup 'groupQuery' will have the
NameWrapper for the selected choice.  A NameWrapper instance is selected if
it is returned by groupQuery.getModelObject();

Regards,

Mike
I had tried this option and it does not work.

Michael Mosmann wrote:
Hi,

.. i am not sure. The model of RadioGroup should contain, wich item is
selected. The model of Radio should reflect the associated value. So if
model of RadioGroup contains "fr" and Property "selected" of item nr. 3
is "fr" this Radio is selected.

maybe this will help..
mm:)


I have a problem when using the Radio component.
Using a list of languages, where each item is a NameWrapper object
with a property "selected". The property "selected" is associated to the
radio component.
However, when presenting to the user the corresponding list of radios,
the language Polish is true, and not English (it should be the selected
option).

 listLanguages.add(new NameWrapper("English", "en", "", true));
 listLanguages.add(new NameWrapper("German", "de", "", false));
 listLanguages.add(new NameWrapper("French", "fr", "", false));
 listLanguages.add(new NameWrapper("Italian", "it", "", false));
 listLanguages.add(new NameWrapper("Polish", "pl", "", false));

 final RadioGroup groupQuery = new RadioGroup("groupLanguagesQuery",
new Model());
 listLanguagesQuery = new ListView("listLanguagesQuery",listLanguages)
{
           protected void populateItem(ListItem item) {
                String lang =
((NameWrapper)item.getModelObject()).getName();
               item.add(new Label("nameLanguageQuery", new
StringResourceModel(lang, this, null,"XXXX")));
               item.add(new Radio("checkLanguageQuery", new
PropertyModel(item.getModel(), "selected"),groupQuery));
           }
       };
groupQuery.add(listLanguagesQuery);

Any ideas? I really need to solve this issue.

Thank you so much.

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

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

I send the code of the application.
if someone can help me ....


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


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

Thank you for your reply, but with the form the problem is not solved (I attach the code with the form).
Any other idea?

/*
 * HomePage.java
 *
 * Created on July 16, 2009, 3:44 PM
 */
 
package com.myapp.wicket;

import java.util.ArrayList;
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.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

public class HomePage extends BasePage {
    private static final long serialVersionUID = 1L;
    public HomePage() {

        Form form = new Form("form");
        ArrayList<NameWrapper> listLanguages = new ArrayList<NameWrapper>();
        listLanguages.add(new NameWrapper("English", "en", ""));
        listLanguages.add(new NameWrapper("German", "de", ""));
        listLanguages.add(new NameWrapper("French", "fr", ""));
        listLanguages.add(new NameWrapper("Italian", "it", ""));
        listLanguages.add(new NameWrapper("Polish", "pl", ""));

        @SuppressWarnings("unchecked")
        final RadioGroup groupQuery = new RadioGroup("groupLanguagesQuery", new Model<NameWrapper>(listLanguages.get(0)));
        @SuppressWarnings("unchecked")
        ListView listLanguagesQuery = new ListView("listLanguagesQuery",listLanguages) {
            private static final long serialVersionUID = 1L;
            protected void populateItem(ListItem item) {
                item.add(new Label("nameLanguageQuery", new PropertyModel(item.getModel(),"name")));
                item.add(new Radio("checkLanguageQuery", item.getModel(),groupQuery));
            }
        };
        groupQuery.add(listLanguagesQuery);

        form.add(groupQuery);
        add(form);
    }
}
package com.myapp.wicket;

import org.apache.wicket.IClusterable;

/**
 *
 * @author ctrojahn
 */
public class NameWrapper implements IClusterable {

    private String name;
    private String shortName;
    private String hit;
    private boolean selected;

    public NameWrapper() {
    }


    public NameWrapper(String name) {
        this.name = name;
    }



    /**
     *
     * @param name
     * @param shortName
     * @param hit
     * @param selec
     */
    public NameWrapper(String name, String shortName, String hit, boolean selec) {
        this.name = name;
        this.shortName = shortName;
        this.hit = hit;
        this.selected = selec;
    }

    public NameWrapper(String name, String shortName, String hit) {
        this.name = name;
        this.shortName = shortName;
        this.hit = hit;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return name;
    }


      /**
     *
     * @return
     */
    public String getShortName() {
        return shortName;
    }

    /**
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 
     * @return
     */
    public String getHit() {
        return hit;
    }

    /**
     *
     * @return
     */
    public boolean getSelected() {
        return selected;
    }

    @Override
    public String toString() {
        return shortName;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

  

}


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

Reply via email to