Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 10
Registered: ‎05-09-2012
My Device: 9780
My Carrier: T-Mobile USA
Accepted Solution

Problem overriding save()

Hello, my app has a screen where I override the save() method.
The new overriden method has a consistency check for an EditField to comtain at least 10 characters.

 

The problem happens when I escape the screen and get the save prompt:
If the EditField has less that 10 characters I get the Dialog.alert that is coded in my overriden save()
then if I push ok the applcation just exits without allowing me to correct the problem and without saving.

How can I make the app not to exit if the cosistency check is triggered?

 

 

public void save() {
   String content = efldContent.getText();
   if (content.length() >= 10) {
       PersistentObject persistentObject;
       final long KEY = 0xa12bb44cff71e9c1L;
       persistentObject = PersistentStore.getPersistentObject(KEY);
       persistentObject.setContents(new ControlledAccess(content));
       persistentObject.commit();
   }else{
       Dialog.alert("content has to be at least 10 characters long");
   }
}

 

 

How can I make the app not to exit if the cosistency check is triggered?

 

Thank you

 

 

 

 

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Problem overriding save()

The Dialog.alert is not suitable for this scenario.

 

You can use Dialog.ask or initiating a Dialog instance and use doModal to block your code and wait for the user response.

 

In both cases, you will get the selected index (or value) and you can continue according to the user selection.

 

E.

Developer
Posts: 455
Registered: ‎03-04-2011
My Device: Paper cup

Re: Problem overriding save()

True, but don't think that's the main issue -- the issue is that once the thread is in save(), there is no way back. The conditional must be done in onSavePrompt, that's exactly what it's for -- to decide whether the app will save, discard, or abort the close. If you pre-check everything there, before calling save(), then you have the chance to kick the user back to the form to fix it, by returning false.
Developer
Posts: 16,783
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem overriding save()

silver is kind of correct. you can also use onSave.
See
http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Contributor
Posts: 10
Registered: ‎05-09-2012
My Device: 9780
My Carrier: T-Mobile USA

Re: Problem overriding save()

Thank you guys!