Building an App with the frostillic.us Framework, Part 5
Mon Jul 21 15:46:09 EDT 2014
- Building an App with the frostillic.us Framework, Part 1
- Building an App with the frostillic.us Framework, Part 2
- Building an App with the frostillic.us Framework, Part 3
- Building an App with the frostillic.us Framework, Part 4
- Building an App with the frostillic.us Framework, Part 5
- Building an App with the frostillic.us Framework, Part 6
- Building an App with the frostillic.us Framework, Part 7
- Define the data model
- Create the view and add it to an XPage
- Create the editing page
- Add validation and translation to the model
- Add notification to the model
- Add sorting to the view
- Basic servlet
- REST with Angular.js
Add notification to the model
The next step in building our Framework app is a simple one: adding some basic visual notification when user saves a note. We'll leave the navigation rule to send the user to the home page in place and use flashScope (included in the Framework) and a "messages" custom control included in the scaffolding DB to add a message.
There are a few places where I could add this code, primarily either the model or the controller. Since it makes sense in this context, I'll add it to the model, via this additional code in the model.Note
class:
@Override protected void postSave() { super.postSave(); FrameworkUtils.flashMessage("confirmation", "Note saved successfully."); }
The flashMessage
method in FrameworkUtils
is a convenience method for exactly this sort of thing. It adds the message string to a List
in the flashScope's property with the provided first parameter plus "Messages". So, in this case, #{flashScope.confirmationMessages}
ends up containing ["Note saved successfully."]
.
These values are read by the xc:messages
control included in the standard xc:layout
control in the scaffolding DB. It outputs both the normal xp:messages
notifications as well as these flash-scoped ones - currently, the classes for the messages are hard-coded in the control and should be tweaked for use with OneUI, Bootstrap, or another UI framework, but eventually I'll shift those out to themes. Since I'm using OneUIv3 for this demo, I set the classes in the control to the appropriate values. The result is a small message that appears on the first load of a subsequent page and disappears thereafter:
Fancy? No, but it doesn't need to be. This same postSave
hook could be used to do much more complex things whenever a note is saved in any context, such as sending a notification email, writing a log entry, or Toaster notification (forgive the missing images on that link).