Logout Button

50 views
Skip to first unread message

Dan

unread,
Oct 27, 2014, 12:28:33 PM10/27/14
to codenameone...@googlegroups.com
I'm trying to put in a logout functionality that essentially wipes the local storage. However, the screen doesn't refresh properly.

It works if the steps are done manually. If I wipe local storage, it'll show the appropriate screen when I run the emulator. However, once logged in, if I wipe local storage, the WelcomeForm isn't refreshed/updated properly.

I've used revalidate to show error messages (using Label.setText(string)) and assumed that revalidate would work too. I've tried overriding the revalidate method in my form, but that just duplicates my form elements.

Code:

public class WelcomeForm extends Form {
    ...
    if(isMGSStorageInitialized())
        showPostLoginForm();
    else
        showLoginForm();
    ...
   
    private boolean isMGSStorageInitialized(){
        try{
            Integer.valueOf((Integer)Storage.getInstance().readObject("INITIALIZED"));
            return true;
        }
        catch(Exception e){
            return false;
        }
    }
   
    private void showPostLoginForm(){
        btnLogout = new Button("Logout");       
        btnLogout.addActionListener(new LogoutButtonActionListener(this));
        addComponent(btnLogout);
    }
    ...
}

public class LogoutButtonActionListener implements ActionListener {

    private WelcomeForm frm;

    public LogoutButtonActionListener(Form frm) {
        this.frm = (WelcomeForm)frm;
    }

    public void actionPerformed(ActionEvent evt) {
        Storage.getInstance().clearStorage();
        this.frm.getComponentForm().revalidate();
    }
}




Shai Almog

unread,
Oct 27, 2014, 9:26:51 PM10/27/14
to codenameone...@googlegroups.com
Relvalidate just lays out the existing form again.
I don't understand why wiping storage should refresh the Form you created?

You can see that storage is deleted and the content of storage in the .cn1 folder under your home directory.

Danny et Diane

unread,
Oct 28, 2014, 7:24:41 AM10/28/14
to codenameone...@googlegroups.com
The first screen asks for a username and password and calls my API to validate and get basic information. This information is stored locally. Once logged in, I can then show the various options available that use the information gathered from the API in storage.

I have the Twitter app on our phone which features a logout which I like. As it's not exclusively my phone, I like logging out when I'm done. I realize this is not the norm.

What part of the class does revalidate call? If the form changes considerably, should I override the method and apply the same logic that occurs when I first instantiate the class?



--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/DopPjSWfybE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/4f94bf87-f691-4282-a052-c9445e5e7b39%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Shai Almog

unread,
Oct 28, 2014, 8:08:19 AM10/28/14
to codenameone...@googlegroups.com
Revalidate just lays out the widgets in the UI it doesn't call any part of your class and has nothing to do with storage.
I don't have a problem with you logging out, I just don't understand your issue?

Danny et Diane

unread,
Oct 28, 2014, 11:43:39 AM10/28/14
to codenameone...@googlegroups.com
Let's see if I can explain this better:

User not logged in = formA (no storage, if statement will display username and password fields to log in)
User logged in = formA (storage exists, if statement will display two buttons: browse and logout)

Example: user logs in, presses browse button and moves along in various screens. Then, he presses the back button until he reaches the main screen. The main screen currently shows username and password fields instead of browse and logout buttons.

How would I refresh the screen to reflect the values in storage? I had assumed that calling revalidate would refresh the screen for future viewing.

Maybe I should have two different screens/forms and instantiate them accordingly and pass them along for back button functionality?


On Tue, Oct 28, 2014 at 9:08 AM, Shai Almog <shai....@gmail.com> wrote:
Revalidate just lays out the widgets in the UI it doesn't call any part of your class and has nothing to do with storage.
I don't have a problem with you logging out, I just don't understand your issue?

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/DopPjSWfybE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

Shai Almog

unread,
Oct 28, 2014, 8:59:10 PM10/28/14
to codenameone...@googlegroups.com
You need to recreate the form and have your logic happen again.
You didn't mention where that if statement is but I assume its in the constructor so you will need to show a new WelcomeForm.

Danny et Diane

unread,
Oct 30, 2014, 12:30:13 PM10/30/14
to codenameone...@googlegroups.com
Just wanted to confirm that instantiating my form in both login and logout events fixed my issue. Thanks!

On Tue, Oct 28, 2014 at 9:59 PM, Shai Almog <shai....@gmail.com> wrote:
You need to recreate the form and have your logic happen again.
You didn't mention where that if statement is but I assume its in the constructor so you will need to show a new WelcomeForm.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/DopPjSWfybE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
Reply all
Reply to author
Forward
0 new messages