hi,
here is my code:

public class AttributeChoiceDto implements Serializable
{
   public AttributeChoiceDto(String aId, String aName)
   {
       theId = aId;
       theName = aName;
   }

   public String getId()
   {
       return theId;
   }

   public void setId(String aId)
   {
       theId = aId;
   }

   public String getName()
   {
       return theName;
   }

   public void setName(String aName)
   {
       theName = aName;
   }

   private String theId;
   private String theName;

}

public class ChoiceOptions extends AbstractModel
{
   public ChoiceOptions(List<AttributeChoiceDto> aOptions)
   {
       theOptions = aOptions;
   }
   public Object getObject(final Component component)
   {
       return theOptions;
   }
   public void setObject(final Component component, final Object object)
   {

   }
}

public class SymbolAddUpdate extends WebPage
{
   public SymbolAddUpdate(PageParameters aParams)
   {
       addFeedback();
       addPageTitle("Add/Update Symbol");

CompoundPropertyModel mySymbol = checkNewOrUpdate(aParams, aParams.getString("theSymbolId"));

       final Form myForm = new AddUpdateForm("form.symbol", mySymbol);
       add(myForm);

       TextField myName = new TextField("name");

       final ChoiceOptions myOptions = new ChoiceOptions(
               theDao.findAllCategoriesAsDto());

       final ChoiceRenderer myRenderer = new ChoiceRenderer("name", "id");

       final CategoryChoices myCategories = new CategoryChoices();
       DropDownChoice myCat
= new DropDownChoice("categories", myCategories, myCategories,myRenderer);
               [...]
}

I hope this helps.

thanks,
florian

Igor Vaynberg wrote:
if you show me the exact code snippet that doesnt work that will give me the necessary context.

-igor


On 5/17/07, *Florian Hehlen* < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> 
wrote:

    Hi,

    Thanks for the help... It's starting to make more sense to me
    although still not working. The issue is definitely with the form
    model. because all my sandbox experiments show me that it all goes
    to hell when i introduce the model in the form. My form is a a
    bean wrapped in a CompoundPropertyModel.

    Maybe you can clarify below your explanation in that context.

    florian

    Igor Vaynberg wrote:
    if you type it it looks like this

    DDC<T>(String,IModel<T>,IModel<List<T>>,IChoiceRenderer<T>)

    the first model is the one that holds the selection, the second
    is the one that holds a list of available choices.

    the constructor with a single model:

    DDC<T>(String,IModel<List<T>>,IChoiceRenderer<T>)

    is used when you use DDC in combination with a compound property
    model on the form, in which case the ddc's id is used as a
    property expression into form's model to determine the selection.
    there is a great wiki page on models.

    so try this

     myForm.add(new DropDownChoice("select",new Model(),new
    MyChoices(),myRenderer));

    this will create a ddc with a null selection. its not practical,
    because to get the selection you have to call
    ddc.getmodelobject(), but it will at least get you going before
    you decide on what model to use.


    -igor


    On 5/16/07, *Florian Hehlen* < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
    wrote:

        hi,

        I am new to wicket so I am not sure how simple this issue is.

        I am creating DropDownChoice components. I want to a)  build
        the the
        Options from a list of Objects (not primitives) and b) want
        to render
        the option id and value as an attribute of the object in the
        list. this
        definitly works in the following sample code:

        public class WicketSandbox extends WebPage
        {
            public WicketSandbox()
            {
                addPageTitle("Development Sandbox");
                final Form myForm = new Form("form");
                add(myForm);

                final ChoiceRenderer myRenderer = new
        ChoiceRenderer("name", "id");
                myForm.add(new DropDownChoice("select",new
        MyChoices(),myRenderer));

            }
        }

        But as soon as I add an IModel to the form it seems that the
        DropDownChoice looks up the choices in the form's IModel.  I
        have tried
        to use the other constructors for the DropDownChoice which
        require an
        (String id, IModel model, IModel choices, IChoicerenderer
        renderer) but
        I can't figure out what is the difference between the 2
        IModel objects
        that have to be provided. If I provide twice a ref to the
        same object I
        get a different error:

        The expression 'id' is neither an index nor is it a method
        for the list class java.util.ArrayList

        this is an improvement because it is accessing the right
        object and
        retrieving the list of choices but not extracting the the
        objects from
        the list as it does when I use (String id, IModel choices,
        IChoicerenderer renderer).

        In all cases if I remove the ChoiceRenderer my web page
        builds and
        displays but I see object.toString() values in my drop-downs.

        Any tips or pointers would be greatly appreciated.

        Florian Hehlen

        
-------------------------------------------------------------------------
        This SF.net email is sponsored by DB2 Express
        Download DB2 Express C - the FREE version of DB2 express and
        take
        control of your XML. No limits. Just data. Click to get it now.
        http://sourceforge.net/powerbar/db2/
        _______________________________________________
        Wicket-user mailing list
        Wicket-user@lists.sourceforge.net
        <mailto:Wicket-user@lists.sourceforge.net>
        https://lists.sourceforge.net/lists/listinfo/wicket-user


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

    -------------------------------------------------------------------------
    This SF.net email is sponsored by DB2 Express
    Download DB2 Express C - the FREE version of DB2 express and take
    control of your XML. No limits. Just data. Click to get it now.

    http://sourceforge.net/powerbar/db2/
    ------------------------------------------------------------------------

    _______________________________________________
    Wicket-user mailing list
    Wicket-user@lists.sourceforge.net
     <mailto:Wicket-user@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/wicket-user

    -------------------------------------------------------------------------
    This SF.net email is sponsored by DB2 Express
    Download DB2 Express C - the FREE version of DB2 express and take
    control of your XML. No limits. Just data. Click to get it now.
    http://sourceforge.net/powerbar/db2/
    _______________________________________________
    Wicket-user mailing list
    Wicket-user@lists.sourceforge.net
    <mailto:Wicket-user@lists.sourceforge.net>
    https://lists.sourceforge.net/lists/listinfo/wicket-user


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

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
------------------------------------------------------------------------

_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to