does this work without wickettester?

-igor

On Mon, Oct 6, 2008 at 2:24 PM, dukehoops <[EMAIL PROTECTED]> wrote:
>
> Sure, here it is below. Test selects a non-default value from
> 'publicLocationChoices' drop down. Problems are:
> -on form submit, LocationSelectionPanel.convertInput() is not called (have
> breakpoint there)
> -in debugger, I can see dropDown's rawInput changing on form submit, but
> model's object ('data') value is never updated
>
> Test
>    public void testLocationSelectionPanel_SelectCohost() {
>        final WicketTester t = getTester();
>        final VirtualEventFormBean formBean = new VirtualEventFormBean();
>        formBean.setEventId(EVENT_ID);
>        formBean.setOrganizerId(currentUser.getId());
>        final EventLocation initialLocation =
> virtualEventService.getCustomSpaceEventLocation(currentUser.getId());
>        formBean.setLocation(initialLocation);
>
>        LocationSelectionPanelTestPage p = new
> LocationSelectionPanelTestPage(formBean);
>        t.startPage(p);
>        t.assertRenderedPage(LocationSelectionPanelTestPage.class);
>
>        DropDownChoice publicLocationsChoice = (DropDownChoice)
> t.getComponentFromLastRenderedPage("form:location:publicLocationChoices");
> //selecting component
>
>        FormTester ft = t.newFormTester("form");
>
>        //select cohost
>        ft.select("location:publicLocationChoices", 1); //select 1st public
> location
>
>        //submit
>        ft.submit();
>        EventLocation newLocation = p.getFormBean().getLocation();
>        assertNotSame(initialLocation, newLocation);
>        assertTrue(newLocation instanceof PublicEventLocation);
>    }
>
> Test Page
> public class LocationSelectionPanelTestPage extends AbstractWebPage {
>
>    @SpringBean private VirtualEventService virtualEventService;
>
>    private final VirtualEventFormBean formBean;
>    private CompoundPropertyModel model;
>
>    public LocationSelectionPanelTestPage(VirtualEventFormBean formBean) {
>        assert formBean != null;
>        this.formBean = formBean;
>        model = new CompoundPropertyModel(formBean);
>        Form form = new Form("form", model);
>        add(form);
>
>        //location selection
>        final CustomSpaceEventLocation organizerLocation =
> virtualEventService.getCustomSpaceEventLocation(formBean.getOrganizerId());
>        //assemble cohost models
>        List<CustomSpaceEventLocation> cohostLocations = new
> ArrayList<CustomSpaceEventLocation>();
>        for (Serializable cohostId : formBean.getCohosts()) {
>            CustomSpaceEventLocation cohostLocation =
> virtualEventService.getCustomSpaceEventLocation(cohostId);
>            cohostLocations.add(cohostLocation);
>        }
>
>        LocationSelectionPanel locationSelectionPanel = new
> LocationSelectionPanel(
>                "location",
>                organizerLocation,
>                cohostLocations,
>                virtualEventService.getPublicEventLocations(),
>                formBean);
>
>        form.add(locationSelectionPanel);
>    }
>
>    public VirtualEventFormBean getFormBean() {
>        return formBean;
>    }
> }
>
> Custom Component In Question
> public class LocationSelectionPanel extends FormComponentPanel {
>
>    //final private PublicLocationRadio publicLocationRadio;
>    final private RadioGroup locationGroup;
>    final private PublicLocationDropDownChoice publicLocationDropDown;
>    final private VirtualEventFormBean formBean;
>    //final private BoundCompoundPropertyModel model;
>    //final static String LOCATION_PROPERTY = "location";
>    final private Model publicLocationModel = new Model();
>    final private Model locationGroupModel = new Model();
>    final private CustomSpaceEventLocation organizerLocation;
>
>    public LocationSelectionPanel(
>            String wicketId,
>            CustomSpaceEventLocation organizerLocation,
>            List<CustomSpaceEventLocation> cohostLocations,
>            List<PublicEventLocation> publicLocations,
>            VirtualEventFormBean formBean) {
>
>        super(wicketId);
>        assert organizerLocation != null;
>        assert cohostLocations != null;
>        assert publicLocations != null;
>        assert formBean != null;
>
>        this.formBean = formBean;
>        this.organizerLocation = organizerLocation;
>
>        this.setRequired(true);
>
>        //model = new BoundCompoundPropertyModel(formBean);
>        this.setModel(new Model(formBean.getLocation()));
>        //model.bind(this, LOCATION_PROPERTY);
>
>
>        //group will default to location specified in formBean.location
>        locationGroup = new RadioGroup("locationGroup", locationGroupModel);
>        locationGroup.setRequired(true);
>        add(locationGroup); //bind RadioGroup's model object to location
> property of this.model's formBean
>
>        // organizer's apt
>        CustomSpaceRadio organizerRadio = new
> CustomSpaceRadio("organizerLocation", organizerLocation);
>        locationGroup.add(organizerRadio);
>
>        //co-hosts' places
>        //create radio controls for cohosts' locations
>        ListView participantChoices = new
> CohostLocationListView("cohostLocationChoices", cohostLocations);
>        locationGroup.add(participantChoices);
>
>        //drop down for public locations
>        publicLocationDropDown = new
> PublicLocationDropDownChoice("publicLocationChoices", publicLocations);
>        add(publicLocationDropDown);
>
>        // radio for selecting public location
>        PublicLocationRadio publicLocationRadio = new
> PublicLocationRadio("publicLocation");
>        locationGroup.add(publicLocationRadio);
>    }
>
>    @Override
>    protected void onBeforeRender() {
>
>        //set child model's based on location property
>        final Object modelObject = getModelObject();
>
>        EventLocation location = (EventLocation) modelObject;
>        assert location != null;
>
>        if (location instanceof CustomSpaceEventLocation) {
>            locationGroupModel.setObject(location);
>            publicLocationModel.setObject(null);
>        } else if (location instanceof PublicEventLocation) {
>            publicLocationModel.setObject(location);
>            locationGroupModel.setObject(location);
>        } else {
>            throw new IllegalStateException("location property of unknown
> type: " + location);
>        }
>
>        //enable drop-down only if public location radio is selected
>        //publicLocationDropDown.setEnabled(location instanceof
> PublicEventLocation);
>
>        //render children
>        super.onBeforeRender();
>    }
>
>
>
>
>    /**
>     * check whether publicLocationRadio is selected. if so,
> setConvertedInput
>     * to publicLocationDropDown's model object, else to radioGroup's
>     */
>    @Override
>    protected void convertInput() {
>
>        Object convertedInput = null;
>
>        EventLocation locGroupModelObject = (EventLocation)
> locationGroup.getConvertedInput();
>        assert locGroupModelObject != null;
>
>        if (locGroupModelObject instanceof CustomSpaceEventLocation) {
>            //TODO always true because locationGroup's model is never null
>            convertedInput = locationGroup.getConvertedInput();
>        } else {
>            convertedInput =
> publicLocationDropDown.getConvertedInput();//publicLocationModel.getObject();
>        }
>
>        setConvertedInput(convertedInput);
>    }
>
>    private class PublicLocationDropDownChoice extends DropDownChoice {
>
>        public PublicLocationDropDownChoice(String wicketId,
> List<PublicEventLocation> publicLocations) {
>            super(wicketId, publicLocationModel, publicLocations, new
> PublicEventLocationChoiceRenderer());
>        }
>    }
>
>    private class PublicLocationRadio extends Radio {
>
>        public PublicLocationRadio(String wicketId) {
>            super(wicketId);
>            setModel(publicLocationModel);
>        }
>    }
>
>    private class PublicEventLocationChoiceRenderer implements
> IChoiceRenderer {
>
>        public Object getDisplayValue(Object object) {
>            if (object instanceof PublicEventLocation) {
>                return ((PublicEventLocation) object).getName();
>            }
>            return null;
>        }
>
>        public String getIdValue(Object object, int index) {
>            return String.valueOf(index);
>        }
>    }
>
>    private class CohostLocationListView extends ListView {
>
>        public CohostLocationListView(String wicketId,
> List<CustomSpaceEventLocation> cohostLocations) {
>            super(wicketId, cohostLocations);
>        }
>
>        protected void populateItem(ListItem item) {
>            item.add(new CustomSpaceRadio("cohostLocation",
> (CustomSpaceEventLocation) item.getModelObject()));
>        }
>    }
> }
>
>
>
> -----
> ----------------
> Nikita Tovstoles
> vside.com
> ----------------
>
> --
> View this message in context: 
> http://www.nabble.com/Custom-Radio-component-with-children--tp19804341p19846733.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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]

Reply via email to