Dear Eelco and all other users

Thanks for your reply. That would solve my problem partially but create another problem that is it would go to the server for every letter, and I want to send it on a click without submitting the form (forgot to mention it in the previous mail). However I solved both in a twisted manner. I require your comment on it. Thanks.
AjaxValueFetcherFallbackLink  is a component I used to encapsulate the link and its decorator. Using this link I can also get multiple client side values. Waiting for you comments.

Imran
(code is as follows)


import java.util.Hashtable;

import javax.servlet.http.HttpServletRequest;

import bd.com.uign.view.wicket.component.AjaxValueFetcherFallbackLink;

import wicket.ajax.AjaxEventBehavior;
import wicket.ajax.AjaxRequestTarget;
import wicket.ajax.IAjaxCallDecorator;
import wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
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;
import wicket.model.PropertyModel;
import wicket.protocol.http.WebRequest;

public class AutherizationPageSample extends WebPage {

    private static final long serialVersionUID = 1887L;

    SampleTextArea area;

    String areaModel = "Imran M Yousuf";

    public AutherizationPageSample() {
        area = new SampleTextArea("area");
        Hashtable<String, String> tab = new Hashtable<String, String>();
        tab.put("areaVal", "document.form.area.value");
        AjaxValueFetcherFallbackLink vLink = new AjaxValueFetcherFallbackLink("link", tab){

            private static final long serialVersionUID = 7751025052489069898L;

            @Override
            public void onClick(AjaxRequestTarget arg0) {
                System.out.println(getParamValue("areaVal"));
            }
           
        };
        add(vLink);
        AjaxFallbackLink link = new AjaxFallbackLink("plainLink") {
            private static final long serialVersionUID = 9001L;

            @Override
            public void onClick(AjaxRequestTarget arg0) {
                System.out.println("Area Value: " + getParamValue("areaVal"));
            }

            public String getParamValue(String param) {
                return ((WebRequest) getRequest()).getHttpServletRequest()
                        .getParameter(param);
            }

            @Override
            protected IAjaxCallDecorator getAjaxCallDecorator() {
                return new IAjaxCallDecorator() {

                    private static final long serialVersionUID = 7554800459242943083L;

                    public CharSequence decorateScript(CharSequence inScript) {
                        String outScript = inScript.toString();
                        /**
                         * The original value is as like as follows
                         */
                        // "var
                        // wcall=wicketAjaxGet('/LogWeb/authapp?wicket:interface=:0:link::IBehaviorListener&wicket:behaviorId=0',
                        // function() { }, function() { });";
                       
                        /**
                         * value to be fetched is to be added as follows
                         */
                        // areaVal='+document.form.area.value+'&
                        HttpServletRequest req = ((WebRequest) getRequest())
                                .getHttpServletRequest();
                        int ind = outScript.indexOf(req.getServletPath() + "?");
                        outScript = outScript.subSequence(0, ind
                                + (req.getServletPath() + "?").length())
                                + "areaVal='+document.form.area.value+'&"
                                + outScript.substring((req.getServletPath() + "?").length() + ind);
                        return outScript;
                    }

                    public CharSequence decorateOnSuccessScript(
                            CharSequence inScript) {
                        // TODO Auto-generated method stub
                        return inScript;
                    }

                    public CharSequence decorateOnFailureScript(
                            CharSequence inScript) {
                        // TODO Auto-generated method stub
                        return inScript;
                    }

                };
            }

        };
        add(link);
        add(new SampleForm("form"));

    }

    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());
            setResponsePage(AutherizationPageSample.class);
        }
    }

    public class SampleTextArea extends TextArea {

        private static final long serialVersionUID = 7751025052489069898L;
        private String latestText = "Imran";

        public SampleTextArea(String arg0) {
            super(arg0);
            setModel(new PropertyModel(this, "latestText"));
//            add(new AjaxEventBehavior("onchange") {
//
//                private static final long serialVersionUID = -8267664816411165266L;
//
//                @Override
//                protected void onEvent(AjaxRequestTarget target) {
//                    System.out.println("Current Value: "
//                            + ((WebRequest) getComponent().getRequest())
//                                    .getHttpServletRequest().getParameter(
//                                            "areaVal"));
//                }
//
//                @Override
//                protected CharSequence getCallbackScript() {
//                    String seq = "var wcall=wicketAjaxGet('/LogWeb/authapp?areaVal='+document.form.area.value+'&wicket:interface=:0:form:area::IBehaviorListener&wicket:behaviorId=1', function() { }, function() { });";
//                    //
//                    return seq;
//                }
//            });
            add( new AjaxFormComponentUpdatingBehavior("onchange"){

                private static final long serialVersionUID = 265707290544450891L;

                @Override
                protected void onUpdate(AjaxRequestTarget arg0) {
                    System.out.println("UPDATED: " + latestText);
                }
               
            });
        }

        public String getLatestText() {
            return latestText;
        }

        public void setLatestText(String latestText) {
            this.latestText = 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