I would like to use different functions like favorites and appointments for one user. I need login data in the app. But is it possible to use local storage in Tabris Framework?
3 Answers
Tabris has a Client Service called ClientStore (RWT.getClient().getService( ClientStore.class) ) to save information on the device. Anyway, it's not recommended to save those data on the device. The recommended way is to store a token with the ClientStore to identify the user when he opens the app the next time. With this token you can store the data e.g. in a data base on the server. The ClientStore can be compared with cookies for a web browser. You never save to much data in a cookie.

- 437
- 2
- 4
I'm about to use the ClientStorage, too. Right now I'm testing a few things with Tabris and I used the guide from here http://eclipsesource.com/blogs/2013/02/18/tabris-0-11-0-new-noteworthy/ .
I'm test setting a ClientStorage object from the value "false" to "true". But every time I exit the app and get back in, the value is back to "false" again.
private void createContent( final UIContext context ) {
final ClientStore storageLogin = RWT.getClient().getService( ClientStore.class );
storageLogin.add( "username", "none" );
storageLogin.add( "passwd", "none" );
storageLogin.add( "isLoggedIn", "false");
labelUsername = new Label( containerContent, SWT.NONE );
labelUsername.setText( "Username:" );
final Text usernameText = new Text( containerContent, SWT.BORDER );
final Label labelPasswd = new Label( containerContent, SWT.NONE );
labelPasswd.setText( "Password:" );
final Text passwdText = new Text( containerContent, SWT.PASSWORD | SWT.BORDER );
final Button buttonLogin = new Button( containerContent, SWT.PUSH );
if(storageLogin.get( "isLoggedIn" ) == "false"){
buttonLogin.setText( "Log in" );
}
else{
buttonLogin.setText( "Logged in!" );
}
buttonLogin.addSelectionListener( new SelectionListener() {
public void widgetSelected( SelectionEvent event ) {
if(storageLogin.get( "isLoggedIn" ) == "false"){
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append( "Username: " + usernameText.getText() + "\n" );
stringBuilder.append( "Password: " + passwdText.getText() + "\n" );
System.out.println( "Stringbuilder: \n" + stringBuilder.toString() );
storageLogin.add( "username", usernameText.getText() );
storageLogin.add( "passwd", passwdText.getText() );
storageLogin.add( "isLoggedIn", "true" );
buttonLogin.setText( "Logged in!" );
}
else{
}
}
public void widgetDefaultSelected( SelectionEvent e ) {
}
} );
}
Of course I won't safe any passwords in cleartext, just experimenting around. :)

- 3
- 2
I would say this is because you execute storageLogin.add( "isLoggedIn", "false"); everytime you access the app. This will override the transfered value and store it back to the client. I would recommend only setting it to false if storageLogin.get( "isLoggedIn" ); returns null.

- 437
- 2
- 4