Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Login widget

    Hi,

    Is there a login widget in smartgwt. I vaguely remember that I browsed the showcase last week and came by a loginwidget or some example showing how a login widget was created, but now I can't find it.

    Is that because it doesn't exist or because I haven't remembered correctly.

    Best Regards
    Niels

    #2
    There is a isc.showLoginDialog in SmartClient but seems like that API is missing from SmartGWT.

    Comment


      #3
      I think the idea of a built in login dialog is a little silly, but my boss made me use it. Here is the quick code I threw together to use it in a sort of GWTish fashion.

      LoginDialog.java
      Code:
      import com.google.gwt.core.client.JavaScriptObject;
      import com.google.gwt.user.client.rpc.AsyncCallback;
      
      public class LoginDialog {
        
        private static native void callBooleanFunction(Object functionX, boolean answer) /*-{
          functionX(answer);
        }-*/;
        
        
        public static void showLoginDialog(final LoginCallback callback) {
          nativeLoginDialog(new NativeCallback() {
            public void loginAttempt(String username, String password, final JavaScriptObject function) {
              callback.loginAttempt(username, password, new AsyncCallback<Boolean>() {
                public void onFailure(Throwable caught) {
                  callBooleanFunction(function,false);
                }
                public void onSuccess(Boolean result) {
                  callBooleanFunction(function,result);
                }          
              });
            }
          });
        }
        
        private static native void nativeLoginDialog(Object callback) /*-{
          $wnd.isc.showLoginDialog(function(value,dialogCallback) {
            var username = value == null ? null : value.username;
            var password = value == null ? null : value.password;
            callback.@edu.umn.msi.tropix.webgui.client.ui.dialog.LoginDialog$NativeCallback::loginAttempt(Ljava/lang/String;Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;)(username,password,dialogCallback);
          });
        }-*/;
      
        interface NativeCallback {
          public void loginAttempt(String username, String password, JavaScriptObject function);
        }
      }
      LoginCallback.java
      Code:
      package edu.umn.msi.tropix.webgui.client.ui.dialog;
      
      import com.google.gwt.user.client.rpc.AsyncCallback;
      
      public interface LoginCallback {
        public void loginAttempt(String username, String password, AsyncCallback<Boolean> validLogin);
      }
      The idea is to call LoginDialog.showLoginDialog with a LoginCallback, that takes in the username, password, and another callback for confirming the login. This third callback is just an AsyncCallback from the GWT client package. Call onSuccess(true) to verify the login is correct, or onSuccess(false) or onFailure(reason) if the login is incorrect.

      There are better ways to do this I am sure, and I don't want a big critique of this throw away code. But it works, and if anyone wants to use it feel free.

      Comment


        #4
        I create the showLoginDialog implementation for SmartGWT:

        LoginDialogCallback interface:
        ==============================
        Code:
        package com.smartgwt.client.util;
        
        /**
         * @author Tercio F. Gaudencio Filho
         */
        public interface LoginDialogCallback
        {
        	public boolean validateCredential(String username, String password);
        }
        showLoginDialog implementation:
        ===============================

        Code:
        /**
         * Handle a complete login interaction with a typical login dialog asking for username and password credentials.
         * <P>
         * As with other convenience methods that show Dialogs, such as +link{classMethod:isc.warn()}, the dialog is shown and the function immediately returns. When the user responds,
         * the provided callback function is called.
         * <P>
         * If the user clicks the "Log in" button, the credentials entered by the user are passed to the provided "loginFunc" as an Object with properties "username" and "password"
         * (NOTE: both property names are all lowercase), as the variable "credentials". For example:
         * 
         * <pre>
         * { username: &quot;barney&quot;, password: &quot;rUbbL3&quot; }
         * </pre>
         * <P>
         * The "loginFunc" should then attempt to log in by whatever means is necessary. The second parameter to the loginFunc, "dialogCallback", is a function, which must be called
         * <i>whether login succeeds or fails</i> with a true/false value indicating whether login succeeded.
         * <P>
         * If the login dialog is dismissable (settable as properties.dismissable, default false) and the user dismisses it, the loginFunc will be fired with null for the credentials.
         * <P>
         * The following code shows typical usage. This code assumes you have created a global function sendCredentials() that send credentials to some authentication system and fires
         * a callback function with the result:
         * 
         * <pre>
         * SC.showLoginDialog(new LoginDialogCallback()
         * {
         * 	public boolean validateCredential(String username, String password)
         * 	{
         * 		return sendCredentials(username, password);
         * 	}
         * });
         * </pre>
         * 
         * The login dialog has several built-in behaviors:
         * <ul>
         * <li>keyboard focus is automatically placed in the username field
         * <li>hitting enter in the username field proceeds to the password field
         * <li>hitting enter in the password field submits (fires the provided callback)
         * </ul>
         * In addition to normal properties supported by Dialog/Window, the following special properties can be passed:
         * <ul>
         * <li><code>username</code>: initial value for the username field
         * <li><code>password</code>: initial value for the password field
         * <li><code>usernameTitle</code>: title for the username field
         * <li><code>passwordTitle</code>: title for the password field
         * <li><code>errorMessage</code>: default error message on login failure
         * <li><code>loginButtonTitle</code>: title for the login button
         * <li><code>dismissable</code>: whether the dialog can be dismissed, default false
         * <li><code>errorStyle</code>: CSS style for the error message, if shown
         * </ul>
         * 
         * @param callback
         *            Callback to fire when the user clicks the login button.
         * 
         */
        public static native void showLoginDialog(LoginDialogCallback callback) /*-{
        	$wnd.isc.showLoginDialog(
        		function(credentials, dialogCallback)
        		{
        			if (credentials == null) return;
        	    	var username = credentials["username"];
        	    	var password = credentials["password"];
        	    	var result = callback.@com.smartgwt.client.util.LoginDialogCallback::validateCredential(Ljava/lang/String;Ljava/lang/String;)(username, password);
        			dialogCallback(result);
        		}
        	);
        }-*/;
        The showLoginDialog should be implemented in the SC class.

        Comment


          #5
          Have an error.
          Implicit super constructor Window() is not visible. Must explicitly invoke another constructor
          http://stackoverflow.com/questions/3904355/how-to-resolve-implicit-super-constructor-classa-is-not-visible-must-explici
          didnt help

          can somebody help me?

          whould be great if author or somebody post login/registration tutorial to
          http://java2s.com/Code/Java/GWT/CatalogGWT.htm
          I really need this. Thank you.

          Comment


            #6
            okay, i already find it, http://uptick.com.au

            Comment

            Working...
            X