Dear users,

I have a situation where I need to get a value from a text area without submitting the form. To do this I think Ajax is the perfect candidate, but I cant get the value. How do I get that value from Ajax? Thanks for the help in advance. I am using the following code:


import wicket.ajax.AjaxEventBehavior;
import wicket.ajax.AjaxRequestTarget;
import wicket.ajax.markup.html.AjaxFallbackLink;
import wicket.markup.html.WebPage;
import wicket.markup.html.form.Form;
import wicket.markup.html.form.TextArea;
import wicket.model.Model;

public class AutherizationPageSample extends WebPage{

    private static final long serialVersionUID = 1887L;
    SampleTextArea area;
    String areaModel = "Imran M Yousuf";
   
    public AutherizationPageSample(){
        area = new SampleTextArea("area");
        area.setModel(new Model(areaModel));
        AjaxFallbackLink link = new AjaxFallbackLink ("link"){
            private static final long serialVersionUID = 9001L;

            @Override
            public void onClick(AjaxRequestTarget arg0) {
                // TODO Auto-generated method stub
                System.out.println("Value: "+ area.getValue());
                System.out.println("Has Raw: "+ area.hasRawInput());
                System.out.println("Raw In: "+ area.getRawInput());
                System.out.println("Model Str: "+ area.getModelObjectAsString());
                System.out.println("Model Obj: "+ area.getModelObject());
                System.out.println("Latest: "+ area.getLatest());
            }
           
        };
        add(new SampleForm("form"));
        add(link);
       
    }
    public class SampleForm extends Form{

        private static final long serialVersionUID = 1011L;

        public SampleForm(String arg0) {
            super(arg0);
            add(area);
        }
        public void onSubmit(){
            System.out.println("Area Value: " + area.getValue());
           
        }
    }
    public class SampleTextArea extends TextArea{
       
        private String latestText;

        public SampleTextArea(String arg0) {
            super(arg0);
            add(new AjaxEventBehavior("onchange"){

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    System.out.println("Changed " + getComponent().getModelObject());
                }
               
            });
        }
       
        public String getLatest(){
            return "Latest";
        }
       
        public String getLatestText(){
            return latestText;
        }
    }
}

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to