You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bigcalm <jo...@intercity-comms.com> on 2009/03/20 15:32:16 UTC

DropDownChoice confusion!

Heya,  I'm trying to figure out the "best" way of handling drop down choices. 
It seems a bit overcomplicated and I'm not sure we're using them in the
correct way?!!

The database function to retrieve my data will be:

List<FixedCharges> listFc = enquiryController.getAvailableFixedCharges("");

....
So I now have a list of primitive hibernate objects with lots of getters and
setters.
....
I want my dropdownchoice to use more than one field from my original
FixedCharges list for the description, so the text in the description field
is...

fixedCharges.getDescription() + " - " + fixedCharges.getValue();

The key value I want returned though, is the unique key from that
table/object - fixedCharges.getFChargeCode();

....
I've already worked out a couple of ways to do it, but I don't like either
of them!!

My first way was to iterate through the fixedcharges list and create a
DropDownItem array before adding it to the form.  This seems an unnecessary
iteration and I'd quite like to have the full fixedCharge object back when
the form is submitted (which this method prevents - I have to go and
reselect it from the database).  
My second way was to try to use a separate custom IChoiceRenderer class, but
I don't really like this method either, it seems very complex and difficult
to extend to a general case scenario.  I don't really want to have
bazillions of IChoiceRenderer implementations one for every class I want a
drop down list on.  Maybe I could have an implementation of the
IChoiceRenderer as an unnamed inner class (which would be best I think) but
I can't figure out how you do this.

What's the best way to do it?   It must be a reasonably common problem.

Cheers!
-- 
View this message in context: http://www.nabble.com/DropDownChoice-confusion%21-tp22621465p22621465.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: DropDownChoice confusion!

Posted by francesco dicarlo <ev...@gmail.com>.
have you considered the use of a Renderer in the dropdownChoice?

DropDownChoice(java.lang.String id, IModel model, java.util.List data,
IChoiceRenderer renderer)

FixedCharges selected=new FixedCharges();

DropdownChoice drop=new DropdownChoice("YourId",new
CompoundPropertyModel(selected),listFc ,new
ChoiceRenderer("YourDisplayExpression","YourIdExpression"));

Cheers

2009/3/20 Bigcalm <jo...@intercity-comms.com>
>
> Heya,  I'm trying to figure out the "best" way of handling drop down choices.
> It seems a bit overcomplicated and I'm not sure we're using them in the
> correct way?!!
>
> The database function to retrieve my data will be:
>
> List<FixedCharges> listFc = enquiryController.getAvailableFixedCharges("");
>
> ....
> So I now have a list of primitive hibernate objects with lots of getters and
> setters.
> ....
> I want my dropdownchoice to use more than one field from my original
> FixedCharges list for the description, so the text in the description field
> is...
>
> fixedCharges.getDescription() + " - " + fixedCharges.getValue();
>
> The key value I want returned though, is the unique key from that
> table/object - fixedCharges.getFChargeCode();
>
> ....
> I've already worked out a couple of ways to do it, but I don't like either
> of them!!
>
> My first way was to iterate through the fixedcharges list and create a
> DropDownItem array before adding it to the form.  This seems an unnecessary
> iteration and I'd quite like to have the full fixedCharge object back when
> the form is submitted (which this method prevents - I have to go and
> reselect it from the database).
> My second way was to try to use a separate custom IChoiceRenderer class, but
> I don't really like this method either, it seems very complex and difficult
> to extend to a general case scenario.  I don't really want to have
> bazillions of IChoiceRenderer implementations one for every class I want a
> drop down list on.  Maybe I could have an implementation of the
> IChoiceRenderer as an unnamed inner class (which would be best I think) but
> I can't figure out how you do this.
>
> What's the best way to do it?   It must be a reasonably common problem.
>
> Cheers!
> --
> View this message in context: http://www.nabble.com/DropDownChoice-confusion%21-tp22621465p22621465.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


Re: DropDownChoice confusion!

Posted by Bigcalm <jo...@intercity-comms.com>.
Excellent - thankyou all for your responses!

I've gone for an inner class in the end and it's all nice and simple and
easy to understand, here's my snippet


        List ebillingCharges =
enquiryController.getAvailableFixedCharges("C", "E", "");
                
        DropDownChoice charges = new DropDownChoice(
                "fixedChargesChoice", 
                new PropertyModel(this, "selected"),
                ebillingCharges, 
                new IChoiceRenderer<FixedCharges>(){ 
                    @Override 
                    public Object getDisplayValue(FixedCharges fixedCharges) 
                    { 
                        return fixedCharges.getDescription() + " - " +
fixedCharges.getValue(); 
                    } 

                    public String getIdValue(FixedCharges fixedCharges, int
index) 
                    { 
                        return fixedCharges.getFchargeCode(); 
                    } 
                });
        
        form.add(charges);

---
Many thanks for all your help!

-- 
View this message in context: http://www.nabble.com/DropDownChoice-confusion%21-tp22621465p22621756.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: DropDownChoice confusion!

Posted by Will Jaynes <wi...@jaynes.org>.
Or, another way,

IChoiceRenderer<FixedCharges> cr = new IChoiceRenderer<FixedCharges>(){

            public Object getDisplayValue(FixedCharges fixedCharges)
            {
                return fixedCharges.getDescription() + " - " +
fixedCharges.getValue();
            }

            public String getIdValue(FixedCharges fixedCharges, int index)
            {
                return fixedCharges.getValue();
            }

        };

On Fri, Mar 20, 2009 at 10:32 AM, Bigcalm <jo...@intercity-comms.com>wrote:

>
> Heya,  I'm trying to figure out the "best" way of handling drop down
> choices.
> It seems a bit overcomplicated and I'm not sure we're using them in the
> correct way?!!
>
> The database function to retrieve my data will be:
>
> List<FixedCharges> listFc = enquiryController.getAvailableFixedCharges("");
>
> ....
> So I now have a list of primitive hibernate objects with lots of getters
> and
> setters.
> ....
> I want my dropdownchoice to use more than one field from my original
> FixedCharges list for the description, so the text in the description field
> is...
>
> fixedCharges.getDescription() + " - " + fixedCharges.getValue();
>
> The key value I want returned though, is the unique key from that
> table/object - fixedCharges.getFChargeCode();
>
> ....
> I've already worked out a couple of ways to do it, but I don't like either
> of them!!
>
> My first way was to iterate through the fixedcharges list and create a
> DropDownItem array before adding it to the form.  This seems an unnecessary
> iteration and I'd quite like to have the full fixedCharge object back when
> the form is submitted (which this method prevents - I have to go and
> reselect it from the database).
> My second way was to try to use a separate custom IChoiceRenderer class,
> but
> I don't really like this method either, it seems very complex and difficult
> to extend to a general case scenario.  I don't really want to have
> bazillions of IChoiceRenderer implementations one for every class I want a
> drop down list on.  Maybe I could have an implementation of the
> IChoiceRenderer as an unnamed inner class (which would be best I think) but
> I can't figure out how you do this.
>
> What's the best way to do it?   It must be a reasonably common problem.
>
> Cheers!
> --
> View this message in context:
> http://www.nabble.com/DropDownChoice-confusion%21-tp22621465p22621465.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: DropDownChoice confusion!

Posted by James Carman <jc...@carmanconsulting.com>.
Do you have a base class for your hibernate entities?  If so, you
could create a default renderer that uses the id value from that base
class.  Also, you could just make sure you have a toString()
implemented for stuff you want to go in the drop downs.

On Fri, Mar 20, 2009 at 10:32 AM, Bigcalm
<jo...@intercity-comms.com> wrote:
>
> Heya,  I'm trying to figure out the "best" way of handling drop down choices.
> It seems a bit overcomplicated and I'm not sure we're using them in the
> correct way?!!
>
> The database function to retrieve my data will be:
>
> List<FixedCharges> listFc = enquiryController.getAvailableFixedCharges("");
>
> ....
> So I now have a list of primitive hibernate objects with lots of getters and
> setters.
> ....
> I want my dropdownchoice to use more than one field from my original
> FixedCharges list for the description, so the text in the description field
> is...
>
> fixedCharges.getDescription() + " - " + fixedCharges.getValue();
>
> The key value I want returned though, is the unique key from that
> table/object - fixedCharges.getFChargeCode();
>
> ....
> I've already worked out a couple of ways to do it, but I don't like either
> of them!!
>
> My first way was to iterate through the fixedcharges list and create a
> DropDownItem array before adding it to the form.  This seems an unnecessary
> iteration and I'd quite like to have the full fixedCharge object back when
> the form is submitted (which this method prevents - I have to go and
> reselect it from the database).
> My second way was to try to use a separate custom IChoiceRenderer class, but
> I don't really like this method either, it seems very complex and difficult
> to extend to a general case scenario.  I don't really want to have
> bazillions of IChoiceRenderer implementations one for every class I want a
> drop down list on.  Maybe I could have an implementation of the
> IChoiceRenderer as an unnamed inner class (which would be best I think) but
> I can't figure out how you do this.
>
> What's the best way to do it?   It must be a reasonably common problem.
>
> Cheers!
> --
> View this message in context: http://www.nabble.com/DropDownChoice-confusion%21-tp22621465p22621465.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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