GWT Remember username and password

145 views
Skip to first unread message

Ice13ill

unread,
Jan 8, 2009, 6:28:52 AM1/8/09
to Google Web Toolkit
I'm trying to remember the username and password in a gwt login
applicaion.
I found this:
1. adding a textbox and passwordbox in the html file

<input type="text" id="1" name="text"/>
<input type="password" id="2" name="password"/>

(i read that if i add those in the html file, the browser will
automatically remember the values).

2. DOM.getElementById for each of them

m_tbUsername = TextBox.wrap(DOM.getElementById("1"));
m_tbUsername.addKeyboardListener(this);

m_tbPassword = PasswordTextBox.wrap(DOM.getElementById("2"));
m_tbPassword.addKeyboardListener(this);
I also added a Login button with a ClickListener

Problem:
neither of those above (textbox, passwordbox, button) will respond to
key or click actions

So...
public void onClick(Widget sender) {
Window.alert("b");
}
does nothing

What's the problem ?
Can somebody tell me another method in gwt for remembering username
and password ? (a link or tip )

todd....@gmail.com

unread,
Jan 8, 2009, 12:48:15 PM1/8/09
to Google Web Toolkit
I had tried something similar only I was trying to move my textboxes
into a popup after the GWT app loaded. Not recalling the exact error
message, I can tell you that it was a problem with GWT not having
created the elements itself.

Add a form to your HTML and wrap it. The addFormHandler will work.

fp = FormPanel.wrap(DOM.getElementById("loginHolder"), true);
fp.addFormHandler(new FormHandler() { ......

Ahmet Meric

unread,
Jan 9, 2009, 3:23:14 AM1/9/09
to Google Web Toolkit
you should use cookies.

On 8 Ocak, 19:48, "todd.sei...@gmail.com" <todd.sei...@gmail.com>
wrote:

Lothar Kimmeringer

unread,
Jan 9, 2009, 3:29:56 AM1/9/09
to Google-We...@googlegroups.com
Ahmet Meric schrieb:
> you should use cookies.

How do Cookies and the autocomplete-functionality of a browser
work together? The OP was not talking about the "remember
my login"-feature some sites offer but the autocomplete-feature
of many browsers that prefill the fields with entries that have
been done in the past (e.g. search-terms being entered into
the search-field of Google).


Regards, Lothar

Martin Trummer

unread,
Jan 9, 2009, 8:27:33 AM1/9/09
to Google Web Toolkit
what I do is: have a hidden html-form in my html page:
<div id="hiddenLoginDiv" style="display:none" >
<form id="hiddenLoginForm" method="post" action="dummy.html"
onsubmit="javascript:return false;">
<input id="username" name="username" type="text" size="20"
maxlength="100" />
<input id="password" name="password" type="password" size="20"
maxlength="100" />
<input id="hiddenLoginFormSubmitButton" type="submit" />
</form>
</div>

in my entry-point I simply read those values and set them into my gwt-
text and gwt-password fields.
if the html values are empty, my gwt-fields will also be empty (this
is always the case when the user enters the site for the first time).
when the user then clicks my login-button:
* I copy the values from my gwt-fields back to the html-fields in the
hidden form
* then I call click on the hidden form's submit button (which will
NOT submit the form, see onsubmit())
this triggers the browsers passwordmanager
* then I proceed with my own login-routine on the server

NOTES:
* I am not sure, that this will work in all browsers password
managers - I think some browsers require the form to really be
submitted
anyway: it works well in firefox 3
* http://code.google.com/docreader/#p=google-web-toolkit-incubator&s=google-web-toolkit-incubator&t=LoginSecurityFAQ
* to trigger the form submit:
/**
* will trigger the submit action of the dummy login form for
password managers
* the form will not be submitted, because the onSubmit function will
always return false.
* note: calling form.submit() instead of calling button.click() will
not call the onSubmit
* function but submit the form immediately.
*/
public static native void submitHiddenLoginForm() /*-{
$doc.getElementById('hiddenLoginFormSubmitButton').click();
}-*/;

JT

unread,
Feb 3, 2009, 9:52:14 PM2/3/09
to Google Web Toolkit
Awesome, thanks for the tips on getting started. It's working well for
me too:

I use this JSNI to get values...

private native String getUsernameFromHTML()
/*-{
return $doc.getElementById("username").value;
}-*/;

private native String getPasswordFromHTML()
/*-{
return $doc.getElementById("password").value;
}-*/;

and this to set....

public static native void submitHiddenLoginForm(String
usernameValue, String passwordValue)
/*-{
var userField = $doc.getElementById("username");
userField.value = usernameValue;

var passField = $doc.getElementById("password");
passField.value = passwordValue;

$doc.getElementById('hiddenLoginFormSubmitButton').click();
}-*/;
>  *http://code.google.com/docreader/#p=google-web-toolkit-incubator&s=go...
Reply all
Reply to author
Forward
0 new messages