You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by tim532 <ti...@gmail.com> on 2008/12/04 01:26:54 UTC

Updating Form TextField Value

Hopefully this is a simple question with a simple answer... For reasons I
can't quite grasp yet, the button to changeName doesn't change the textfield
value when I click it.  However, the submit button does work to change the
value of the textfield, and setting the initial default value of the
textfield works too.  

Can someone enlighten this new Wicket developer?  I've tried to search for a
similar question but it seems too basic.. 

The form:

<form wicket:id="editForm">

  <input type="text" id="name" wicket:id="name" />
  <input type="submit" wicket:id="changeName" value="changeName" />
  <input type="submit" wicket:id="saveButton" value="save" />

</form>

With code as such:

public class SimpleExample extends BasePage{
	
	private String name = "defaultName";
	
	public String getName() {return name;}
	public void setName(String name) {	this.name = name;}

	public SimpleExample() {
		Form editForm = new Form("editForm", new CompoundPropertyModel(this)) {
			public void onSubmit()
			{
				name = "afterSubmit";
			}
		};
		
		Button b = new Button("changeName") { 
			public void onSubmit() {
				SimpleExample.this.name = "testName";
			}
		}.setDefaultFormProcessing(false);
		
		TextField txtCode = new TextField("name");
		editForm.add(b);
		editForm.add(txtCode);
		editForm.add(new Button("saveButton"));
		add(editForm);
	}
}

Thanks,
Tim

-- 
View this message in context: http://www.nabble.com/Updating-Form-TextField-Value-tp20824843p20824843.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: Updating Form TextField Value

Posted by Dane Laverty <da...@chemeketa.edu>.
I think you'll want to use the <button> tag rather than the <input
type="submit> for the "changeName" button.

-----Original Message-----
From: tim532 [mailto:tim.hu532@gmail.com] 
Sent: Wednesday, December 03, 2008 4:27 PM
To: users@wicket.apache.org
Subject: Updating Form TextField Value


Hopefully this is a simple question with a simple answer... For reasons
I
can't quite grasp yet, the button to changeName doesn't change the
textfield
value when I click it.  However, the submit button does work to change
the
value of the textfield, and setting the initial default value of the
textfield works too.  

Can someone enlighten this new Wicket developer?  I've tried to search
for a
similar question but it seems too basic.. 

The form:

<form wicket:id="editForm">

  <input type="text" id="name" wicket:id="name" />
  <input type="submit" wicket:id="changeName" value="changeName" />
  <input type="submit" wicket:id="saveButton" value="save" />

</form>

With code as such:

public class SimpleExample extends BasePage{
	
	private String name = "defaultName";
	
	public String getName() {return name;}
	public void setName(String name) {	this.name = name;}

	public SimpleExample() {
		Form editForm = new Form("editForm", new
CompoundPropertyModel(this)) {
			public void onSubmit()
			{
				name = "afterSubmit";
			}
		};
		
		Button b = new Button("changeName") { 
			public void onSubmit() {
				SimpleExample.this.name = "testName";
			}
		}.setDefaultFormProcessing(false);
		
		TextField txtCode = new TextField("name");
		editForm.add(b);
		editForm.add(txtCode);
		editForm.add(new Button("saveButton"));
		add(editForm);
	}
}

Thanks,
Tim

-- 
View this message in context:
http://www.nabble.com/Updating-Form-TextField-Value-tp20824843p20824843.
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: Updating Form TextField Value

Posted by tim532 <ti...@gmail.com>.
That was exactly it.  Thanks for that explanation!

Cheers,
Tim


Jeremy Thomerson-5 wrote:
> 
> It doesn't have to do with your html input vs. button.  It's because
> default
> form processing is turned off, the form model doesn't fire that it was
> changed, so the model doesn't go back to your getName() method to get it's
> value.
> 
> You can add this in your button onSubmit:
> getForm().modelChanged();
> 
> 
> 
> -- 
> Jeremy Thomerson
> http://www.wickettraining.com
> 
> 
> On Wed, Dec 3, 2008 at 6:26 PM, tim532 <ti...@gmail.com> wrote:
> 
>>
>> Hopefully this is a simple question with a simple answer... For reasons I
>> can't quite grasp yet, the button to changeName doesn't change the
>> textfield
>> value when I click it.  However, the submit button does work to change
>> the
>> value of the textfield, and setting the initial default value of the
>> textfield works too.
>>
>> Can someone enlighten this new Wicket developer?  I've tried to search
>> for
>> a
>> similar question but it seems too basic..
>>
>> The form:
>>
>> <form wicket:id="editForm">
>>
>>  <input type="text" id="name" wicket:id="name" />
>>  <input type="submit" wicket:id="changeName" value="changeName" />
>>  <input type="submit" wicket:id="saveButton" value="save" />
>>
>> </form>
>>
>> With code as such:
>>
>> public class SimpleExample extends BasePage{
>>
>>        private String name = "defaultName";
>>
>>        public String getName() {return name;}
>>        public void setName(String name) {      this.name = name;}
>>
>>        public SimpleExample() {
>>                Form editForm = new Form("editForm", new
>> CompoundPropertyModel(this)) {
>>                        public void onSubmit()
>>                        {
>>                                name = "afterSubmit";
>>                        }
>>                };
>>
>>                Button b = new Button("changeName") {
>>                        public void onSubmit() {
>>                                SimpleExample.this.name = "testName";
>>                        }
>>                }.setDefaultFormProcessing(false);
>>
>>                TextField txtCode = new TextField("name");
>>                editForm.add(b);
>>                editForm.add(txtCode);
>>                editForm.add(new Button("saveButton"));
>>                add(editForm);
>>        }
>> }
>>
>> Thanks,
>> Tim
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Updating-Form-TextField-Value-tp20824843p20824843.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
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Updating-Form-TextField-Value-tp20824843p20825050.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: Updating Form TextField Value

Posted by Jeremy Thomerson <je...@wickettraining.com>.
It doesn't have to do with your html input vs. button.  It's because default
form processing is turned off, the form model doesn't fire that it was
changed, so the model doesn't go back to your getName() method to get it's
value.

You can add this in your button onSubmit:
getForm().modelChanged();



-- 
Jeremy Thomerson
http://www.wickettraining.com


On Wed, Dec 3, 2008 at 6:26 PM, tim532 <ti...@gmail.com> wrote:

>
> Hopefully this is a simple question with a simple answer... For reasons I
> can't quite grasp yet, the button to changeName doesn't change the
> textfield
> value when I click it.  However, the submit button does work to change the
> value of the textfield, and setting the initial default value of the
> textfield works too.
>
> Can someone enlighten this new Wicket developer?  I've tried to search for
> a
> similar question but it seems too basic..
>
> The form:
>
> <form wicket:id="editForm">
>
>  <input type="text" id="name" wicket:id="name" />
>  <input type="submit" wicket:id="changeName" value="changeName" />
>  <input type="submit" wicket:id="saveButton" value="save" />
>
> </form>
>
> With code as such:
>
> public class SimpleExample extends BasePage{
>
>        private String name = "defaultName";
>
>        public String getName() {return name;}
>        public void setName(String name) {      this.name = name;}
>
>        public SimpleExample() {
>                Form editForm = new Form("editForm", new
> CompoundPropertyModel(this)) {
>                        public void onSubmit()
>                        {
>                                name = "afterSubmit";
>                        }
>                };
>
>                Button b = new Button("changeName") {
>                        public void onSubmit() {
>                                SimpleExample.this.name = "testName";
>                        }
>                }.setDefaultFormProcessing(false);
>
>                TextField txtCode = new TextField("name");
>                editForm.add(b);
>                editForm.add(txtCode);
>                editForm.add(new Button("saveButton"));
>                add(editForm);
>        }
> }
>
> Thanks,
> Tim
>
> --
> View this message in context:
> http://www.nabble.com/Updating-Form-TextField-Value-tp20824843p20824843.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
>
>