This is sort of a refinement to:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/99c259aad06406c6/f7fb27b8fa47760d?lnk=gst&q=GWT+recaptcha#f7fb27b8fa47760d

The idea here is I wanted a captcha control that I can insert in my
GWT Dialogs. I have pasted the composite below to share. A little bit
of a hack because of the creation of "Label dummyLable = new Label();"
and manipulating the Element to set the ID attribute. Prerequisite to
using this control is to load the reCaptcha script:

<script type="text/javascript" src="http://api.recaptcha.net/js/
recaptcha_ajax.js"></script>

public class CaptchaComposite extends Composite {
        private Grid grid = new Grid(1, 1);
        private static final String DIV_NAME = "recaptcha_div";

        public CaptchaComposite() {

                this.initWidget(grid);

                Label dummyLable = new Label();
                grid.setWidget(0, 0, dummyLable);
                Element divElement = dummyLable.getElement();
                divElement.setAttribute("id", DIV_NAME);
        }

        private void createChallenge() {
                createNewChallengeJSNI();
        }

        public String getChallengeField() {
                String value = getChallengeJSNI();
                PMLogger.debug("challenge=" + value);
                return value;
        }
        public String getResponse() {
                String value = getResponseJSNI();
                PMLogger.debug("response=" + value);
                return value;
        }


    private native String getResponseJSNI()
    /*-{
      return $wnd.Recaptcha.get_response();
    }-*/;

    private native String getChallengeJSNI()
    /*-{
      return $wnd.Recaptcha.get_challenge();
    }-*/;

    private native void createNewChallengeJSNI()
    /*-{
                $wnd.Recaptcha.create("<your public key here>",
                "recaptcha_div", {
                   theme: "red",
                   callback: $wnd.Recaptcha.focus_response_field
                });
    }-*/;

    private native void reloadChallengeJSNI()
    /*-{
                $wnd.Recaptcha.reload();
    }-*/;

    private native void destroyJSNI()
    /*-{
                $wnd.Recaptcha.destroy();
    }-*/;

        public void createNewChallenge() {
                reloadChallengeJSNI();
        }

        public void destroyCaptcha() {
                destroyJSNI();
        }

        @Override
        protected void onAttach() {
                super.onAttach();
                createChallenge();
        }

}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to