You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by goody44 <ma...@spidertracks.co.nz> on 2010/07/07 03:44:46 UTC

Dropdownchoice selection to trigger change of form

Hi, I would of thought that this would be fairly basic to figure out but I
just can't get it to work. I have a dropdownchoice in one form and then
another form below it. Based on the selection of the dropdown I want the
contents of the other form to change. I have an ajax listener that add the
form to be rendered on a selection change.
Anyone know what I am doing wrong or has any examples?

Thanks! 	


@Override
	protected void setup() {

		vehicleIndex = -1;
		user = new UserDetachableModel();

		Fragment fragment = null;

		if (user.getObject().getVehicles() != null) {
			this.vehicleIndex = 0;
		}
		final AddVehicleFormPanel addVehicleFormPanel = new
AddVehicleFormPanel("addVehiclePanel", new PropertyModel<Vehicle>(this,
"selectedVehicle"));
		addVehicleFormPanel.setOutputMarkupId(true);

		// final AddVehicleForm form = new AddVehicleForm("addVehicle",
		// getSelectedVehicle());

		CompoundPropertyModel<MyVehiclesPanel> formModel = new
CompoundPropertyModel<MyVehiclesPanel>(
				this);

		// form.setDefaultModel(formModel);

		setDefaultModel(formModel);

		// check if user has vehicles
		if (user.getObject().getVehicles() != null) {
			fragment = new Fragment("dropDown", "vehiclesExist", this);

			DropDownChoice<Vehicle> vehiclesDropDown = new DropDownChoice<Vehicle>(
					"vehicleSelect", new PropertyModel<Vehicle>(this,
							"selectedVehicle"),
					new PropertyModel<List<Vehicle>>(user, "vehicles"),
					new WebOptionStringChoiceRender<Vehicle>());

			vehiclesDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {

				private static final long serialVersionUID = 1L;

				@Override
				protected void onUpdate(AjaxRequestTarget target) {
					
					target.addComponent(addVehicleFormPanel);
				}

			});
			fragment.add(vehiclesDropDown);

		} else {
			fragment = new Fragment("dropDown", "noVehicles", this);
		}

		add(fragment);
		// addVehicleFormPanel.add(form);
		add(addVehicleFormPanel);
	}

	public void setSelectedVehicle(Vehicle selectedVehicle) {
		vehicleIndex = user.getObject().getVehicles().indexOf(selectedVehicle);
	}

	/**
	 * 
	 * @return Vehicle The selected vehicle
	 */
	public Vehicle getSelectedVehicle() {

		Vehicle returned = null;

		if (vehicleIndex == -1) {

			List<Vehicle> vehicles = this.user.getObject().getVehicles();

			if (vehicles != null && vehicles.size() > 0) {
				vehicleIndex = 0;
				returned = vehicles.get(0);
			}
		} else {
			returned = user.getObject().getVehicles().get(vehicleIndex);
		}

		return returned;
	}
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dropdownchoice-selection-to-trigger-change-of-form-tp2280387p2280387.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 selection to trigger change of form

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
First of all.. I would not use vehicleIndex. Take that away.

**
Martin

2010/7/7 goody44 <ma...@spidertracks.co.nz>:
>
> Thanks for your reply.
> I tried what you said plus a lot of variation but haven't got it to work
> yet. Using the ajax debugger I noticed that the panel is getting rerendered
> but not with the new data. Could be a problem with my models. How would you
> do it if you had a child panel that has a nested form and you want to change
> the data of the form?
> Thanks for your help
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dropdownchoice-selection-to-trigger-change-of-form-tp2280387p2280461.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 selection to trigger change of form

Posted by goody44 <ma...@spidertracks.co.nz>.
Thanks for your reply.
I tried what you said plus a lot of variation but haven't got it to work
yet. Using the ajax debugger I noticed that the panel is getting rerendered
but not with the new data. Could be a problem with my models. How would you
do it if you had a child panel that has a nested form and you want to change
the data of the form?
Thanks for your help
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dropdownchoice-selection-to-trigger-change-of-form-tp2280387p2280461.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 selection to trigger change of form

Posted by Russell Simpkins <ru...@hotmail.com>.
I think you are neglecting to do any changes in your "onupdate()" method. When onupdate is called, the user should have selected a vehicle, which would populate "selectedVehicle" - you need to then populate your other dropdown menu or whatever else you wanted to populate before you addOrReplace to your container and finally addComponent to the target. You made no changes before calling: target.addComponent(addVehicleFormPanel); 
I would think that if you tried:
setup();target.addComponent(addVehicleFormPanel);
You may get the results you are after. Also, given that you plan on refreshing elements, I think you should consider using addOrReplace().
Russ

> Date: Tue, 6 Jul 2010 18:44:46 -0700
> From: matthew@spidertracks.co.nz
> To: users@wicket.apache.org
> Subject: Dropdownchoice selection to trigger change of form
> 
> 
> Hi, I would of thought that this would be fairly basic to figure out but I
> just can't get it to work. I have a dropdownchoice in one form and then
> another form below it. Based on the selection of the dropdown I want the
> contents of the other form to change. I have an ajax listener that add the
> form to be rendered on a selection change.
> Anyone know what I am doing wrong or has any examples?
> 
> Thanks! 	
> 
> 
> @Override
> 	protected void setup() {
> 
> 		vehicleIndex = -1;
> 		user = new UserDetachableModel();
> 
> 		Fragment fragment = null;
> 
> 		if (user.getObject().getVehicles() != null) {
> 			this.vehicleIndex = 0;
> 		}
> 		final AddVehicleFormPanel addVehicleFormPanel = new
> AddVehicleFormPanel("addVehiclePanel", new PropertyModel<Vehicle>(this,
> "selectedVehicle"));
> 		addVehicleFormPanel.setOutputMarkupId(true);
> 
> 		// final AddVehicleForm form = new AddVehicleForm("addVehicle",
> 		// getSelectedVehicle());
> 
> 		CompoundPropertyModel<MyVehiclesPanel> formModel = new
> CompoundPropertyModel<MyVehiclesPanel>(
> 				this);
> 
> 		// form.setDefaultModel(formModel);
> 
> 		setDefaultModel(formModel);
> 
> 		// check if user has vehicles
> 		if (user.getObject().getVehicles() != null) {
> 			fragment = new Fragment("dropDown", "vehiclesExist", this);
> 
> 			DropDownChoice<Vehicle> vehiclesDropDown = new DropDownChoice<Vehicle>(
> 					"vehicleSelect", new PropertyModel<Vehicle>(this,
> 							"selectedVehicle"),
> 					new PropertyModel<List<Vehicle>>(user, "vehicles"),
> 					new WebOptionStringChoiceRender<Vehicle>());
> 
> 			vehiclesDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
> 
> 				private static final long serialVersionUID = 1L;
> 
> 				@Override
> 				protected void onUpdate(AjaxRequestTarget target) {
> 					
> 					target.addComponent(addVehicleFormPanel);
> 				}
> 
> 			});
> 			fragment.add(vehiclesDropDown);
> 
> 		} else {
> 			fragment = new Fragment("dropDown", "noVehicles", this);
> 		}
> 
> 		add(fragment);
> 		// addVehicleFormPanel.add(form);
> 		add(addVehicleFormPanel);
> 	}
> 
> 	public void setSelectedVehicle(Vehicle selectedVehicle) {
> 		vehicleIndex = user.getObject().getVehicles().indexOf(selectedVehicle);
> 	}
> 
> 	/**
> 	 * 
> 	 * @return Vehicle The selected vehicle
> 	 */
> 	public Vehicle getSelectedVehicle() {
> 
> 		Vehicle returned = null;
> 
> 		if (vehicleIndex == -1) {
> 
> 			List<Vehicle> vehicles = this.user.getObject().getVehicles();
> 
> 			if (vehicles != null && vehicles.size() > 0) {
> 				vehicleIndex = 0;
> 				returned = vehicles.get(0);
> 			}
> 		} else {
> 			returned = user.getObject().getVehicles().get(vehicleIndex);
> 		}
> 
> 		return returned;
> 	}
> -- 
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dropdownchoice-selection-to-trigger-change-of-form-tp2280387p2280387.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
> 
 		 	   		  
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3