a couple of notes
first what you are doing in convertintput() looks to me like it should
be working
you dont need phonemodel/phonemake fields as you dont use them - at
least they are never written to.
isntead of using getinput() inside the model you should try using
getmodelobject()
i would set a breakpoint inside phonemodel's
dropdownchoice.convertinput() and see why its not getting the right
value there
-igor
On Dec 5, 2007 2:35 AM, wicket user <[EMAIL PROTECTED]> wrote:
> Thanks Igor, that's certainly pushed me along in the right direction my only
> problem is that I can't seem to get the value from the selected dropdown,
> there are two drop downs that will always be used but I only care about the
> 2nd value(the phonemodel), the first, phone make, is just a means of
> getting there.
>
> I'm calling convertInput but I think I'm missing in some of my wicket
> knowledge because it isn't working, sooo at the risk of being laughed at by
> the greater wicket community here is my code.
>
> public class PhoneComponentPanel extends FormComponentPanel
> {
> protected final Log logger = LogFactory.getLog(getClass());
>
> PhoneMaker phoneMake;
> Phone phoneModel;
>
> Phone selectedPhone;
>
> DropDownChoice phoneMakeSelect = new DropDownChoice("phoneMake");
> DropDownChoice phoneModelSelect = new DropDownChoice("phoneModel");
>
>
> private List<PhoneMaker> makerList = getPhoneMakers();
> final HashMap<String, List> makeLookup = new HashMap<String, List>();
>
>
> public PhoneComponentPanel(String id)
> {
> super(id);
> init();
> }
> public PhoneComponentPanel(String id, Model model)
> {
> super(id, model);
> init();
> }
>
> private void init()
> {
> logger.debug("Initialising PhoneComponentPanel");
>
> // Create a list of all Make and models
> for(PhoneMaker maker : makerList)
> {
> makeLookup.put(maker.getId(),
> getUtilityService().getPhones(maker));
> }
>
> // Init the Phone Makers Drop Down with a the list of makers
> logger.debug("about to initi phone make");
> phoneMakeSelect.clearInput();
> phoneMakeSelect.setModel(new Model(phoneMake));
> phoneMakeSelect.setRequired(true);
> phoneMakeSelect.setChoices(makerList);
> phoneMakeSelect.setChoiceRenderer(new
> PhoneMakerChoiceRenderer(makerList));
> phoneMakeSelect.add(new
> AjaxFormComponentUpdatingBehavior("onchange")
> {
> protected void onUpdate(AjaxRequestTarget target)
> {
> target.addComponent(phoneModelSelect);
> }
> });
> add(phoneMakeSelect);
>
> // Configure the choices for the model selection, this is dependant
> on what has
> // been select on the make selection
> IModel modelChoices = new AbstractReadOnlyModel()
> {
> public Object getObject()
> {
> List models;
> if (phoneMakeSelect.getInput() == null ||
> phoneMakeSelect.getInput().equals("") )
> {
> // If no maker has been selected then return an empty
> list
> logger.debug("Phone make hasn't been selected returning
> empty model list");
> models = Collections.EMPTY_LIST;
> } else
> {
> // The phone make has been selected
> logger.debug("Phone make has been selected:
> "+phoneMakeSelect.getInput());
> models=makeLookup.get(phoneMakeSelect.getInput());
> }
> return models;
> }
> };
>
> phoneModelSelect.setModel(new Model(phoneModel));
> phoneModelSelect.setChoices(modelChoices);
> phoneModelSelect.setChoiceRenderer(new PhoneChoiceRenderer());
> phoneModelSelect.setOutputMarkupId(true);
> phoneModelSelect.setRequired(true);
>
> // Configure the phone model drop down
> add(phoneModelSelect);
>
> }
>
>
>
> @Override
> protected void convertInput()
> {
> logger.debug("!!!!!!!!!!!! CONVERTING INPUT!!!!!!!!!!!!!!!!!!");
> setConvertedInput(phoneModelSelect.getConvertedInput());
> }
>
>
>
> public PhoneMaker getPhoneMake()
> {
> return phoneMake;
> }
>
> public void setPhoneMake(PhoneMaker phoneMake)
> {
> this.phoneMake = phoneMake;
> }
>
> public Phone getPhoneModel()
> {
> return phoneModel;
> }
>
> public void setPhoneModel(Phone phoneModel)
> {
> this.phoneModel = phoneModel;
> }
>
> }
>
>
> I'm setting this up in a parent form with the Panel being declared as such
>
> phonePanel = new PhoneComponentPanel("subscriber.phone", new
> Model(selectedPhone));
> add(phonePanel);
>
> As always any assistance/ridicule in the right direction would be great.
>
> Cheers
> Simon
>
>
> On 04/12/2007, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> >
> > put them in a formcomponentpanel
> >
> > -igor
> >
> >
> > On Dec 4, 2007 6:14 AM, wicket user <[EMAIL PROTECTED]> wrote:
> > > Hi all,
> > >
> > > I'm now on the second phase of the project I'm working on and starting
> > to
> > > find cases where I'm repeating code which means one thing : refactor.
> > >
> > > As an example I've got two dropdowns that select make and model with a
> > bit
> > > of ajax to populate the second dropdown, these are always going to be
> > > together so it makes sense to permanently couple them and be done with
> > it.
> > >
> > > What is the best way to prevent duplication in a case such as this while
> > > still keeping the ability to validate etc?
> > >
> > > Many thanks
> > > Simon
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]