You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marieke Vandamme <ma...@tvh.be> on 2009/07/08 07:53:24 UTC

setting value in TextField with ajax fails after field had error

Hello, 

Consider my code underneath and following actions:
- Page has a form with a REQUIRED textfield and a button that updates that 
textfield through ajax
- When clicking button the value in textfield is altered with 'hello' => 
Normal situation
- When clearing the textfield again, the onError action of the 
AjaxFormComponentUpdatingBehavior is called, 
   because the value is empty and the field is required
- When clicking the button again the textfield is rewritten, but has an 
empty value instead of 'hello' => ERROR situation

If my explanation isn't enough, please let me know and I try again.
Hope someone can test my code and tell me what I am doing wrong..
Many thanks, Marieke

TestPage.html
----------------------
<form wicket:id="webform">
            <input type="text" wicket:id="acTest"/>
            <input type="button" wicket:id="btnTest" value="set textfield 
value"/>
</form>


TestPage.java
-----------------------
public class TestPage extends WebPage {
    public TestPage(){
        Form webform = new Form("webform", new CompoundPropertyModel(new 
FormBean()));
        add(webform);
        final TextField acTest = new TextField("acTest");
        webform.add(acTest);
        acTest.setRequired(true);
        acTest.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println("onchange - onupdate");
            }
            @Override
            protected void onError(AjaxRequestTarget target, 
RuntimeException e){
                System.out.println("onchange - onerror");
            }
        });

        webform.add(new AjaxLink("btnTest") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                FormBean formBean = 
(FormBean)getPage().get("webform").getDefaultModelObject();
                formBean.setAcTest("hello");
                target.addComponent(acTest);
            }
        });
    }

    public class FormBean implements Serializable{
        private String acTest;
        public FormBean(){
 
        }
        public String getAcTest() {
            return acTest;
        }
        public void setAcTest(String acTest) {
            this.acTest = acTest;
        }
    }
}
**** DISCLAIMER ****
<A HREF="http://www.tvh.be/newen/pages/emaildisclaimer.html">
http://www.tvh.be/newen/pages/emaildisclaimer.html </A>

"This message is delivered to all addressees subject to the conditions
set forth in the attached disclaimer, which is an integral part of this
message."

Re: setting value in TextField with ajax fails after field had error

Posted by Igor Vaynberg <ig...@gmail.com>.
acTest.clearInput();
formBean.setAcTest("hello");
target.addComponent(acTest);

-igor

On Tue, Jul 7, 2009 at 10:53 PM, Marieke
Vandamme<ma...@tvh.be> wrote:
> Hello,
>
> Consider my code underneath and following actions:
> - Page has a form with a REQUIRED textfield and a button that updates that
> textfield through ajax
> - When clicking button the value in textfield is altered with 'hello' =>
> Normal situation
> - When clearing the textfield again, the onError action of the
> AjaxFormComponentUpdatingBehavior is called,
>   because the value is empty and the field is required
> - When clicking the button again the textfield is rewritten, but has an
> empty value instead of 'hello' => ERROR situation
>
> If my explanation isn't enough, please let me know and I try again.
> Hope someone can test my code and tell me what I am doing wrong..
> Many thanks, Marieke
>
> TestPage.html
> ----------------------
> <form wicket:id="webform">
>            <input type="text" wicket:id="acTest"/>
>            <input type="button" wicket:id="btnTest" value="set textfield
> value"/>
> </form>
>
>
> TestPage.java
> -----------------------
> public class TestPage extends WebPage {
>    public TestPage(){
>        Form webform = new Form("webform", new CompoundPropertyModel(new
> FormBean()));
>        add(webform);
>        final TextField acTest = new TextField("acTest");
>        webform.add(acTest);
>        acTest.setRequired(true);
>        acTest.add(new AjaxFormComponentUpdatingBehavior("onchange") {
>            @Override
>            protected void onUpdate(AjaxRequestTarget target) {
>                System.out.println("onchange - onupdate");
>            }
>            @Override
>            protected void onError(AjaxRequestTarget target,
> RuntimeException e){
>                System.out.println("onchange - onerror");
>            }
>        });
>
>        webform.add(new AjaxLink("btnTest") {
>            @Override
>            public void onClick(AjaxRequestTarget target) {
>                FormBean formBean =
> (FormBean)getPage().get("webform").getDefaultModelObject();
>                formBean.setAcTest("hello");
>                target.addComponent(acTest);
>            }
>        });
>    }
>
>    public class FormBean implements Serializable{
>        private String acTest;
>        public FormBean(){
>
>        }
>        public String getAcTest() {
>            return acTest;
>        }
>        public void setAcTest(String acTest) {
>            this.acTest = acTest;
>        }
>    }
> }
> **** DISCLAIMER ****
> <A HREF="http://www.tvh.be/newen/pages/emaildisclaimer.html">
> http://www.tvh.be/newen/pages/emaildisclaimer.html </A>
>
> "This message is delivered to all addressees subject to the conditions
> set forth in the attached disclaimer, which is an integral part of this
> message."
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: setting value in TextField with ajax fails after field had error

Posted by Marieke Vandamme <ma...@tvh.be>.
Hello, 

The onchange is what I need to use, but that's not my problem at all...
Please try my code, and follow the steps I mentioned above my code. 
Has anyone else got a clue? Thanks !


Mathias Nilsson wrote:
> 
> The onchange is only triggered when you type and then go onblur. Check
> onkeypress, onkeydown, onkeyup
> 

-- 
View this message in context: http://www.nabble.com/setting-value-in-TextField-with-ajax-fails-after-field-had-error-tp24385756p24404587.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: setting value in TextField with ajax fails after field had error

Posted by Mathias Nilsson <wi...@gmail.com>.
The onchange is only triggered when you type and then go onblur. Check
onkeypress, onkeydown, onkeyup
-- 
View this message in context: http://www.nabble.com/setting-value-in-TextField-with-ajax-fails-after-field-had-error-tp24385756p24390652.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