unable to get textfield value

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

unable to get textfield value

ganesh kumar
Hi,
        I am unable to get textfield value what went wrong i don't know,I want to get textfield value onclick
and attatch to label dynamically.I am attatching my code
//html
<html xmlns:wicket="http://wicket.apache.org">

<input wicket:id="name" type="text" maxlength="32" />
world
<form wicket:id="productActionForm">
<input type="submit" value="Add to cart" wicket:id="addToCart"/>
</form>
</html>

//java
public class Hello extends WebPage
{
        Label s;
        TextField t;
        public Hello()
        {
        //Label s = new Label("subject", "John");
        //add(s);
       
        t=new TextField("name", new Model(""));
        s = new Label("subject",new Model("before click"));
        add(t);
        add(s);
        Form form = new Form("productActionForm");
        add(form);
        form.add(new Button("addToCart") {
                public void onSubmit() {
                                        String string=t.getDefaultModelObjectAsString();
                        System.out.println(string);
                    s.setDefaultModelObject(string);
          s.setVisible(true);
                }
                });

        }
       
}

Reply | Threaded
Open this post in threaded view
|

Re: unable to get textfield value

jcgarciam
Your Text field is not being submitted within the form, place your <input wicket:id="name" type="text" maxlength="32" /> inside the <form> and also fix the hierarchy in your java file.

On Mon, Aug 8, 2011 at 10:38 AM, ganesh kumar [via Apache Wicket] <[hidden email]> wrote:
Hi,
        I am unable to get textfield value what went wrong i don't know,I want to get textfield value onclick
and attatch to label dynamically.I am attatching my code
//html
<html xmlns:wicket="http://wicket.apache.org">

<input wicket:id="name" type="text" maxlength="32" />
world
<form wicket:id="productActionForm">
<input type="submit" value="Add to cart" wicket:id="addToCart"/>
</form>
</html>

//java
public class Hello extends WebPage
{
        Label s;
        TextField t;
        public Hello()
        {
        //Label s = new Label("subject", "John");
        //add(s);
       
        t=new TextField("name", new Model(""));
        s = new Label("subject",new Model("before click"));
        add(t);
        add(s);
        Form form = new Form("productActionForm");
        add(form);
        form.add(new Button("addToCart") {
                public void onSubmit() {
                                        String string=t.getDefaultModelObjectAsString();
                        System.out.println(string);
                    s.setDefaultModelObject(string);
          s.setVisible(true);
                }
                });

        }
       
}




If you reply to this email, your message will be added to the discussion below:
http://apache-wicket.1842946.n4.nabble.com/unable-to-get-textfield-value-tp3727003p3727003.html
To start a new topic under Apache Wicket, email [hidden email]
To unsubscribe from Apache Wicket, click here.



--

JC 


Reply | Threaded
Open this post in threaded view
|

Re: unable to get textfield value

ganesh kumar
Hi Thanks,
             It's working now i am new to wicket.your suggistion helped me to go forward once again thank you now i am sending working code it may useful to others

//html
<html xmlns:wicket="http://wicket.apache.org">

<form wicket:id="productActionForm">
<input wicket:id="name" type="text" maxlength="32" />
world

<input type="submit" value="Add to cart" wicket:id="addToCart"/>
</form>
</html>

//java
package myapp.hello;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
public class Hello extends WebPage
{
        Label s;
        TextField t;
        public Hello()
        {
        //Label s = new Label("subject", "John");
        //add(s);
Form form = new Form("productActionForm");
        t=new TextField("name", new Model(""));
        s = new Label("subject",new Model("before click"));
        form.add(t);
        form.add(s);
        form.add(new Button("addToCart") {
                public void onSubmit() {
                        String string=t.getDefaultModelObjectAsString();
                        System.out.println(string);
                    s.setDefaultModelObject(string);
          s.setVisible(true);
                }
                });
        add(form);

        }
       
}

Reply | Threaded
Open this post in threaded view
|

Re: unable to get textfield value

jcgarciam
just as suggestion instead of having the wicket component as member of your class, declare the fields that will be backing your component and declare a working model object for them ie:

private String name;
..getter/setters..

... then you can just do...

form.add(new TextField("name", new PropertyModel(this,"user")); 

by using a corresponding model you can take great advantage of wicket programming model, which of course let you do this on your onSubmit (form or button):

public void onSubmit() { 
   System.out.println(this.name);
}

Hope this help.

On Tue, Aug 9, 2011 at 6:46 AM, ganesh kumar [via Apache Wicket] <[hidden email]> wrote:
Hi Thanks,
             It's working now i am new to wicket.your suggistion helped me to go forward once again thank you now i am sending working code it may useful to others

//html
<html xmlns:wicket="http://wicket.apache.org">

<form wicket:id="productActionForm">
<input wicket:id="name" type="text" maxlength="32" />
world

<input type="submit" value="Add to cart" wicket:id="addToCart"/>
</form>
</html>

//java
package myapp.hello;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
public class Hello extends WebPage
{
        Label s;
        TextField t;
        public Hello()
        {
        //Label s = new Label("subject", "John");
        //add(s);
Form form = new Form("productActionForm");
        t=new TextField("name", new Model(""));
        s = new Label("subject",new Model("before click"));
        form.add(t);
        form.add(s);
        form.add(new Button("addToCart") {
                public void onSubmit() {
                        String string=t.getDefaultModelObjectAsString();
                        System.out.println(string);
                    s.setDefaultModelObject(string);
          s.setVisible(true);
                }
                });
        add(form);

        }
       
}




If you reply to this email, your message will be added to the discussion below:
http://apache-wicket.1842946.n4.nabble.com/unable-to-get-textfield-value-tp3727003p3729466.html
To start a new topic under Apache Wicket, email [hidden email]
To unsubscribe from Apache Wicket, click here.



--

JC 


Reply | Threaded
Open this post in threaded view
|

Re: unable to get textfield value

jcgarciam
In reply to this post by ganesh kumar
i made a typo:
form.add(new TextField("name", new PropertyModel(this,"user")); 

should have been:

form.add(new TextField("name", new PropertyModel(this,"name")); 

On Tue, Aug 9, 2011 at 9:24 AM, Juan Carlos Garcia <[hidden email]> wrote:
just as suggestion instead of having the wicket component as member of your class, declare the fields that will be backing your component and declare a working model object for them ie:

private String name;
..getter/setters..

... then you can just do...

form.add(new TextField("name", new PropertyModel(this,"user")); 

by using a corresponding model you can take great advantage of wicket programming model, which of course let you do this on your onSubmit (form or button):

public void onSubmit() { 
   System.out.println(this.name);
}

Hope this help.

On Tue, Aug 9, 2011 at 6:46 AM, ganesh kumar [via Apache Wicket] <[hidden email]> wrote:
Hi Thanks,
             It's working now i am new to wicket.your suggistion helped me to go forward once again thank you now i am sending working code it may useful to others

//html
<html xmlns:wicket="http://wicket.apache.org">

<form wicket:id="productActionForm">
<input wicket:id="name" type="text" maxlength="32" />
world

<input type="submit" value="Add to cart" wicket:id="addToCart"/>
</form>
</html>

//java
package myapp.hello;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
public class Hello extends WebPage
{
        Label s;
        TextField t;
        public Hello()
        {
        //Label s = new Label("subject", "John");
        //add(s);
Form form = new Form("productActionForm");
        t=new TextField("name", new Model(""));
        s = new Label("subject",new Model("before click"));
        form.add(t);
        form.add(s);
        form.add(new Button("addToCart") {
                public void onSubmit() {
                        String string=t.getDefaultModelObjectAsString();
                        System.out.println(string);
                    s.setDefaultModelObject(string);
          s.setVisible(true);
                }
                });
        add(form);

        }
       
}




If you reply to this email, your message will be added to the discussion below:
http://apache-wicket.1842946.n4.nabble.com/unable-to-get-textfield-value-tp3727003p3729466.html
To start a new topic under Apache Wicket, email [hidden email]
To unsubscribe from Apache Wicket, click here.



--

JC 





--

JC