package test.ajaxRadioButtons;

import java.util.Arrays;
import java.util.List;

import wicket.ajax.AjaxRequestTarget;
import wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import wicket.markup.html.basic.Label;
import wicket.markup.html.form.Form;
import wicket.markup.html.form.RadioChoice;
import wicket.model.PropertyModel;

public class TestForm extends Form {
	
	private List options = Arrays.asList(new String[] {"Morning", "Noon", "Evening" });
	private Label label;
	private String choice = (String)options.get(0);

	public TestForm(String id) {
		super(id);
		
		final PropertyModel choiceModel = new PropertyModel(this,  "choice");
		RadioChoice radioChoice = new RadioChoice("radio_address_group", choiceModel, options);
		this.setOutputMarkupId(true);
		label = new Label("label", "Morning");

		
		radioChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
			
			@Override
			protected void onUpdate(AjaxRequestTarget target) {
				System.out.println("Status changed");
				//Doesn't work
				this.getComponent().getParent().get("label").replaceWith(new Label("label", "Clicked"));
				
				//Something to do here
			}
			
		});
		add(radioChoice);
		this.add(label);
	}

	public String getChoice() {
		return choice;
	}


	public void setChoice(String choice) {
		this.choice = choice;
	}
}
