Vaadin 7: Usage of UI vs. Navigator+Views - vaadin

In Vaadin 7, a web application can have multiple entry points; the UIs. Each UI can only have a single Navigator containing Views.
We are working on an application which requires multi-level navigation, and for some screens we don't know if we should have a single UI with a navigator or multiple UIs with a shared menu component.
What are the advantages and inconveniences of UI and Navigator? Are there any guidelines about this choice?

I recommend using one UI with Navigator as in my opinion it's enough to do the job. Main inconvinience of many UIs is reload when switching between them. Also you would need to remember about desired consistency, eg. to have same header in each UI. And from my experience you would for sure encounter more problems ;-)
To make it clean you should use MVP patter. I use similar to this one with com.google.common.eventbus.EventBus to handle events. I add eventBus to my views, post events there and handle them in appropriate presenter, without implementing listeners in view which in my opinion is more problematic. As MVP already reserves 'presenter' and 'view' I call Vaadin view 'page'.
You can create header, footer main menu and then content container (eg. some Layout) to wire navigator with:
Navigator n = new Navigator(UI.getCurrent(), layout);
To manage navigation I created PagesEnum and when changing view I post ChangePageEvent which gets PageEnum.SOME_PAGE as parameter. Optionally there is also an id of item to display. So in MainPresenter I have:
#Subscribe
public void changePage(ChangePageEvent event) {
String url = event.getPageName();
if (event.hasId()) {
url += "/" + event.getEntityId();
}
navigator.navigateTo(url);
}
Then there are different possibilities:
in enter method of the page (Vaadin view) make sure that appropriate submenu is displayed.
add it as parameter to ChangePageEvent and handle it in changePage method.
hardcode it in PageEnum as new field, eg. subMenu and create other enum for submenus, chandle it in changePage method.
Submenu will be probably outside of the container that you wire Navigator with, so there you can create SubMenuPresenter and SubMenuView to handle submenu change.

the subject of your question made me sweat very much in the past 2013.
I studied, analyzed and tested various aspects of Vaadin 7 UIs and Navigator.
I looked a great number of framework, wiki and paper on the subject; related and non related to Vaadin 7.
It was some time ago (in early 2013), I'm not fresh on the subject; anyway these are some of the links I'm able to resurrect:
Vaadin MVP Lite for Vaadin 6
MVP4Vaadin - Basic Principle
Views content switching
Vaadin 7 Navigator problem - Vaadin forum
Sub-navigation - Vaadin forum
Our requirements was somewhat similar to the scenario of Vaadin MVP Lite; but we needed more abstraction and flexibility on the composition of the views.
I tried hard to use the provided Navigator but It wasn't easily customizable.
Navigator is a concrete class. UIs can have only one Navigator.
In the Navigator constructor you can find this line:
this.ui.setNavigator(this);
Navigator do a great job for most application with simple needs and provide nice functionality out of the box, but it isn't really intended for extension or customization.
Another aspect to keep in mind is that when changing view with Navigator, you change all the components on screen; you cannot change small bits.
Then I found this guide that put me on a interesting road:
Composing the User Interface, Chapter 7 - MSDN Microsoft
The article is really nice and illuminating; though it has many commonalities with the way Delphi or any other component based framework work, the 'Region' concept was really a bless.
The other chapters are really interesting too (Modular application development, and MVVP).
In the end we adopted the concept of Region with only one UI.
Briefly it works like this:
There is a GUI component that is able to host other component(s); The places where it can hosts other components are like 'holes'. Each hole is registered and it is a Region bonded to a String name (simple hasmap)
Through the Region name, one can 'put' another Vaadin component in a Region in order to make it visible.
What happens when the UI is inited is that one Region is registered (the entire UI) as the 'root' Region.
Then a component that represent the login form is hosted in the 'root' region.
If a successful login attempt is made then another component is hosted in the 'root' region (removing the login component); this very component is a host too: it registers another Region called 'main' and have a left side navigation menu too.
Now, if one want to display a component (the welcome page, for example) can retrieve the 'main' Region and put the component to display.
Vaadin Navigator implements bookmarking and back button support.
I was sad because we didn't develop it but it was not a requirement for our application.
IMHO, the Vaadin guys did a hard but good decision keeping Navigator simple; state management is not easily implemented. It would be nice for the future have a Navigator more extensible.
Anyway I think current Navigator respond to most average needs.
My answer is longer then foreseen; I hope my effort can help.

Related

Communicating single-spa container app to angular child app

I need a help to communicate from my container single-spa to loaded angular app ( child ). when user click on parent app ( spa-container ) option, that should communicated to child application to change the mode.
it will not happen very frequently. But not able to find a way to communicate from container to loaded angular application.
there is a detail given by spa itself : spa-communication detail but not clear and there is no detailed steps. any one help me?
I'm one of the maintainers of single-spa.
We tend to be light on our opinions in the documentation about how to implement communication between modules because there are a lot of ways to implement it and each comes with pros/cons. In the situation you described it sounds like you might want to explore option #3 from the link you posted.
Custom Browser events
In the parent you fire custom events on the window. API on MDN.
Quick example
// in the parent (usually called the single-spa config or root-config in the documentation)
const event = new CustomEvent("myEvent", {favoriteMovie: 'StarWars'})
window.dispatchEvent(event)
// in the child (or registeredApplication)
window.addEventListener("myEvent", myEventHandlingFunction)
function myEventHandlingFunction(e) {...}
That should at least get you started, there are other options for communication as well and this particular approach isn't going to be the best solution in every situation.
It's also worth noting that customEvents don't work in IE11 unless you include a polyfill.

How to Manage state between tabs in Flutter App

I am using TabBar in my application where I need to get Input in first tab and show
output based on some calculation on other tab.
I am able to get input in first tab but when I click on second tab, my state is lost. I am not sure if I have to make it a Stateful widget at root level.
I am relatively new in Mobile App. Can someone help me out here?
EDIT:
Now I am able to achieve what I said above, but when I am trying to access the list of items from first tab, it throws null exception in second tab?
I solved the above problem using AutomaticKeepAliveClientMixin as described in the answer below.
I think what you may be after is AutomaticKeepAliveClientMixin. I always add that to my screen widgets within TabBarView. This way when a user enters data into fields in one tab and navigates to other tabs and back the data is still there as you would expect.
Then when the user performs an action like "save" I deal with state management (BLoC etc).
You may want to use architecture for managing and sharing states. There are many approaches to manage state:
InheritedWidget to pass app state down the widget hierarchy
Scoped model library to hold app state and notify Widgets of Updates
Redux library to manage app state and update Widgets
Business Logic Components (BLoC)
Check out this article. Check this GitHub repository with different architecture examples

SAPUI5 - Header and Footer for all applications

I'm pretty new to SAPUI5 and have a question:
Is it possible to have for example a base application with a custom Header and footer and to change only the content to the view of another application?
So basically I have for example 3 applications and one base application.
In the base application, there is only a page header and footer. I want to change the page content to the first view of one of the three application (for example based on a parameter, passed in URL).
With another parameter passed in URL, The content changes to the view of the second application.
In dynpros it was possible with subscreens, so a new "application" was inserted as a subscreen.
I hope you understand my question.
What you describe, sounds like the Page navivation concept in UI5, using the Router (as #Bernard said). More info here
You can find a more specific example here which does what you describe. You can reuse the code of this example app using the top right corner icon.
A different scenario is the navigation between different apps. In UI5/Fiori an app is the whole package with its own Component.js. So navigating from one app to another app means to load a new Component.js, start the execution from there, and rerender all the application controls, reset the models, and so on so forth. But this should not scare you if you really want to change the whole context. If you configure your apps correctly, you won't need to download the same libraries again when swtching between apps, because they will be cached. So the browser just needs to rerender (miliseconds for a header and footer).

How can I support user edited content in a complex web application?

I'm building a web site (using ASP.NET, MVC 3, Razor) and I'm not using an off the shelf CMS. This is because I evaluated a lot of existing CMS's, and found them all to have a massive learning curve, tons of features I didn't need, and they force you into a page oriented model. By "page oriented model", I mean that you can specify a general page layout and stylesheets, but the object that the user can edit is a whole page, which displays, for example, in a central panel, and maybe you can customize the sidebars as well.
But this site is very design centric, and needs to be much more fluid and granular than this. By "design-centric", I mean that the site was built in Photoshop by a graphic designer, and there is heavy use of images and complex styling to map the design to HTML/css/js. Also, every page on the site is totally different. There are also UI elements such as accordion panels, in which we need the user to be able to edit the content of each panel, but certainly not the jQuery+HTML that powers the accordion. The users are subject matter experts but very non-technical.
So I'll have a page with lots of complex layout and styling, which I don't want the user to access, but within this there will be, say, a div containing text that I would like the user to be able to edit.
How can I best accomplish this?
So far, I'm implementing this by having snippets, which are little units of html, stored in external files, that the user can edit. In run mode, these are loaded and displayed inline (with a little "Edit This Content" button if you're logged in and have permissions). If you click the Edit button, you get a little WYSIWYG editing screen, where you can edit and save changes. So I can control all the messy stuff, and put in little placeholders for user editable content. But this isn't entirely simple for me, and I'm wondering if there's a better way.
Don't mean to necro this, but it seems to be the most relevant question to what I'm currently researching. I recently built something similar as you described above, but I'm pulling data from a database instead of static files. For each page (like /about or /contact) in the Controller I pull data for that page from the DB in the form of a Json string key/value pair. Key is the placeholder tag, Value is the.. value. After deserializing, I simply populate a list and assign it to a ViewBag, then in the CSHTML I ViewBag.List.Keyname to grab the text.
I have a small admin control panel which allows me to modify the text in the database. Having little hover-overs like you do is a great idea though!
Well, I stuck with my original plan:
So far, I'm implementing this by having snippets, which are little
units of html, stored in external files, that the user can edit. In
run mode, these are loaded and displayed inline (with a little "Edit
This Content" button if you're logged in and have permissions). If you
click the Edit button, you get a little WYSIWYG editing screen, where
you can edit and save changes. So I can control all the messy stuff,
and put in little placeholders for user editable content. But this
isn't entirely simple for me, and I'm wondering if there's a better
way.
It works reasonably well for now.

Wiring two applications in lotus notes

I need to wire two applications so that one reacts when another is selected.
I need a calendar view (populated in one application) to update when a person is selected from a list (based from another application).
I have been trying to do this for absolutely ages and have hit a brick wall as the existing knowledge base is pretty poor. I don't understand how to compose the action required to do this, or how to use the WDSL system to wire the two, which i will be linking using the UNID of the person.
Any help appreciated.
Assuming you are using 8.x+. Look up this example in the designer help: Example 1 - Simple composite application creation using Lotus Notes components

Resources