0
votes

My 'create new User' app can only create one new user. If I want to create an additional user I have to restart the app. What I want to do is, create some button which does this task without restarting the app.

To be more specific, after the initial call of the app I create a new user (include save). The user is stored in the back-end and still visible on the front-end (so I can further edit the user). In case I want to create an additional user, I want to push some button and the view will be restarted/reloaded (and also the Model). Eventually I want the inital state of my app. Then I want to be able to create the next new user (include save) and maybe another one.

What I already tried:

  • 'CrossApplicationNavigation' to my 'create new user' app without any parameters. It works only the first time, because when I push the button the second time nothing happens. The URL stays the same (no parameters are changing).
  • Deleting data of the Model and subsequently calling the oninit() function. But I get problem with refilling the model.

Is there some function or something else I can try?

As descripted in comment (component.js):

     init: function () {

        //set model
        this.setModel(models.createTableModel(this), "table");

             if (this.getComponentData().startupParameters.ID) {
                                var sID = this.getComponentData().startupParameters.ID[0];
                                if (sID !== "") {
                                    this.getModel("table").setProperty("/ID", sID);
                                } else {
                                    this.getModel("table").setProperty("/ID", "");
                                }
                            }

        }
1
Never ever call lifecycle events like onInit yourself. Instead put your init code in a different method. Call this method from the onInit and also later when your button is pressed to reset your view.Marc
But I get problem with refilling the model. Can you elaborate?Marc
@Marc Thanks for the hint. 'But I get problem with refilling the model.': The init function of the component.js is asking for some ID (in the URL). The Problem is, the ID does not change. So iam working with the ID from the first created user. Therefore I can not get to the right functions to refill the model in a proper way.Hammer
Please show some code.Marc

1 Answers

0
votes

I think, you're using a local model? Then you'll have to reset your local model. Reset your local model in onInit function and on pressing button "Add new user".

onInit: function(){
  this.oLocalModel = this.getModel("myLocalModel");
  this._resetModel(this.oLocalModel);
},

_resetModel: function(oModel){
  oModel.setData();
},

onPressAddNewUser: function(){
  this._resetModel(this.oLocalModel);
}