You almost have ripped my code ;) But this is the way I did it, but I don`t 
have to subclass the extended class but use a toDisplayValue-strategy instead.

 
________________________________

From: [EMAIL PROTECTED] on behalf of Matej Knopp
Sent: Sun 17-7-2005 0:41
To: wicket-user@lists.sourceforge.net
Subject: Re: [Wicket-user] customize display-value for choicelist.



Hmm.. I've extended the ChoiceList class to get this behavior. It works,
but I really don't know if there's not a better solution for 1.0.

In 1.1 things have changed and ChoiceList will no longer exist. Johan
Compagner has posted details ~week ago.

As for 1.0, I've done it this way

public class ChoiceListExt extends ChoiceList {

     /** Creates a new instance of ExtChoiceList */
     public ChoiceListExt () {
         super ();
     }

     /**
      * Creates a new instance of ExtChoiceList using given
      * collection.
      * @param choices - the wrapped collection
      */
     public ChoiceListExt (final Collection choices) {
         super (choices);
     }

     private class ExtChoice implements IChoice {
         /** The index of the choice */
         private final int index;

         /** The choice model object */
         private final Object object;

         /**
          * Constructor
          *
          * @param object
          *            The object
          * @param index
          *            The index of the object in the choice list
          */
         public ExtChoice (final Object object, final int index) {
             this.object = object;
             this.index = index;
         }

         /**
          * @see wicket.markup.html.form.model.IChoice#getDisplayValue()
          */
         public String getDisplayValue () {
             return ChoiceListExt.this.getDisplayValue (object);
         }

         /**
          * @see wicket.markup.html.form.model.IChoice#getId()
          */
         public String getId () {
             return Integer.toString (index);
         }

         /**
          * @see wicket.markup.html.form.model.IChoice#getObject()
          */
         public Object getObject () {
             return object;
         }
     }

     /**
      * Creates and returns new choice for object at given index.
      * @param index - index of desired object
      * @param object - this parameters is not used
      */
     protected IChoice newChoice (final Object object, final int index) {
         return new ExtChoice (getList ().get (index), index);
     }

     /**
      * Returns a string describing given object. This is the function
      * user should re-implement to allow arbitrary objects descriptions.
      * @param obj - the object
      * @return string describing the given object
      */
     protected String getDisplayValue (Object obj) {
         return obj.toString ();
     }
}

Creating anonymous instance of ChoiceListExt and overiding
getDisplayValue for each case.

Peter Veentjer - Anchor Men wrote:
> What is the easiest way to customize the display-valuefor the items in the 
> ChoiceList (except overriding the toString of the object itself)? I have been 
> looking through the sources (ChoiceListModel) but I can`t find an easy way. I 
> know I could write an implementation of the ChoiceList where I can control 
> the IChoice creation (and the toDisplayValue implementation) but sounds like 
> a lot of work for such a general problem.
> 
> Maybe it would be an idea to add a toString strategy.
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



<<winmail.dat>>

Reply via email to