Sunday, August 29, 2010

problems with auto-complete form login

Hi,

I implemented a login form suitable for auto-complete by the browser
nearly exactly as described here:

http://borglin.net/gwt-project/?page_id=467

Unfortunately, I have problems with it:

1. The password field is not filled in.

When I login for the first time the browser (FF) asks me to remember
the form fields. I can verify in the browsers settings that the
username and password is stored in the browser.

However, when I login again, only the username field is autofilled.
The password field is empty.

2. I cannot repeat the login.

When I login, logout and then try to login again, the form cannot be
created. The call to Document.get().getElementById(LOGINFORM_ID);
returns null.

I would be glad if someone could help me with this problem!

Below is my code.

Thank you
Magnus

--------------------
index.html:

<!doctype html>
<!-- The DOCTYPE declaration above will set the -->
<!-- browser's rendering engine into -->
<!-- "Standards Mode". Replacing this declaration -->
<!-- with a "Quirks Mode" doctype may lead to some -->
<!-- differences in layout. -->

<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">

<!--
-->
<!-- Consider inlining CSS to reduce the number of requested files
-->
<!--
-->
<link type="text/css" rel="stylesheet" href="ics.css">

<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Isar Chess System</title>

<!-- -->
<!-- This script loads your compiled module. -->
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="ics/
ics.nocache.js"></script>
</head>

<!-- -->
<!-- The body can have arbitrary html, or -->
<!-- you can leave the body empty if you want -->
<!-- to create a completely dynamic UI. -->
<!-- -->
<body>

<!-- OPTIONAL: include this if you want history support -->
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1'
style="position:absolute;width:0;height:0;border:0"></iframe>

<!-- RECOMMENDED if your web app will not function without
JavaScript enabled -->
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-
left: -11em; color: red; background-color: white; border: 1px solid
red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>

  <div class="apl-Indicator" id="apl-Indicator">
    <img src="img/Indicator.gif"  alt="loading">
  </div>

<div id="loginDiv" style="display:none">
<form action="login" id="loginForm">
<table id="loginTable" valign="center">
<tr>
<td id="loginLabel">Username:</td>
</tr>
<tr>
<td><input id="loginUsername" name="u" style="margin-top: 0px"></
td>
</tr>
<tr>
<td id="loginLabel">Password:</td>
</tr>
<tr>
<td><input id="loginPassword" name="pw" type="password"
style="margin: 0px"></td>
</tr>
<tr>
<td id="loginRememberMe"></td>
</tr>
<tr>
<td align='right'>
<button id="loginSubmit" type="submit">Login</button>
</td>
</tr>
</table>
</form>
</div>

</body>
</html>


--------------------
LoginBox.java:

package ics.client.gui.box;

import ics.client.Application;
import ics.client.apl.Command;
import ics.client.gui.cmp.*;

import com.google.gwt.dom.client.*;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import
com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;

public class LoginBox extends Box
{
private static final String LOGINFORM_ID = "loginForm";
private static final String LOGINBUTTON_ID = "loginSubmit";
private static final String REMEMBERME_ID = "loginRememberMe";
private static final String USERNAME_ID = "loginUsername";
private static final String PASSWORD_ID = "loginPassword";

public LoginBox ()
{
build ();
}

public void build ()
{
Element e = Document.get().getElementById(LOGINFORM_ID);
Window.alert ("LoginBox - Element: " + e);

assert (e != null);

FormPanel form = FormPanel.wrap(e, false);

form.setAction("javascript:__gwt_login()");

TableCellElement rememberMeCell = (TableCellElement)
Document.get().getElementById(REMEMBERME_ID);
CheckBox box = new CheckBox("Remember Me");
rememberMeCell.appendChild(box.getElement());

injectLoginFunction(this);

VerticalPanel p = new VerticalPanel ();
p.add(form);
setWidget(p);
}

private native void injectLoginFunction(LoginBox view)
/*-{
$wnd.__gwt_login = function()
{
view.@ics.client.gui.box.LoginBox::doLogin()();
}
}-*/;

private void doLogin()
{
String usr = ((InputElement)
Document.get().getElementById(USERNAME_ID)).getValue();
String pwd = ((InputElement)
Document.get().getElementById(PASSWORD_ID)).getValue();

execute (usr,pwd);
}

private void execute (String usr,String pwd)
{
// process login
}

}

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

No comments:

Post a Comment