Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Vaadin porlets enable PortletHub support automatically? #30

Closed
ujoni opened this issue Sep 23, 2019 · 2 comments
Closed

Can Vaadin porlets enable PortletHub support automatically? #30

ujoni opened this issue Sep 23, 2019 · 2 comments

Comments

@ujoni
Copy link
Contributor

ujoni commented Sep 23, 2019

Find out, if it is possible to enable Portlet Hub for the Vaadin portlets automatically, so that the developer can leverage the Vaadin wrappers for the hub without a care in the world.

Links, where the portlet hub is activated:

@ujoni ujoni added this to Inbox - needs triage in OLD Vaadin Flow ongoing work (Vaadin 10+) Sep 23, 2019
@ujoni ujoni moved this from Inbox - needs triage to Iteration Backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) Sep 23, 2019
@ujoni ujoni changed the title Can Vaadin porlet support enable PortletHub support automatically? Can Vaadin porlets enable PortletHub support automatically? Sep 23, 2019
@pleku pleku moved this from Iteration Backlog to Product backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) Sep 25, 2019
@pleku pleku moved this from Product backlog to Iteration Backlog in OLD Vaadin Flow ongoing work (Vaadin 10+) Oct 2, 2019
@pleku
Copy link

pleku commented Oct 2, 2019

Pluto has a page for Portlet 3.0 features which can be used for testing the hub.
This should provide the understanding on:

  • whether we can automate loading of the hub for the users
  • if we should automate it always
  • or if we just use the standard portlet spec for enabling this, and should document that for the users

If we need to require the users to enable the hub when they want to use IPC features, we should then throw exceptions when they use it without enabling it first.

@caalador caalador self-assigned this Oct 3, 2019
@caalador caalador moved this from Iteration Backlog to In progress in OLD Vaadin Flow ongoing work (Vaadin 10+) Oct 3, 2019
@caalador
Copy link
Contributor

caalador commented Oct 3, 2019

Automating loading of PortletHub is possible when the portlet.xml is in portlet 3 mode
e.g. header should be:

<portlet-app xmlns="http://xmlns.jcp.org/xml/ns/portlet"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/portlet http://xmlns.jcp.org/xml/ns/portlet/portlet-app_3_0.xsd"
             version="3.0">

and then we can in VaadinPortlet have

    @Override
    public void renderHeaders(HeaderRequest request, HeaderResponse response)
            throws PortletException, IOException {
        super.renderHeaders(request, response);
        response.addDependency("PortletHub", "javax.portlet", "3.0.0");
    }

Which will then load the portletHub when we are in portlet 3.0 mode. In portlet 2.0 and 1.0 modes it will just not load anything extra.

The portlet Id is easiest to get from the response, so in the javascripts the $0 is from
VaadinPortletService.getCurrentResponse().getPortletResponse().getNamespace();

After this we can register the portlet to the hub with for instance

if (!window.Vaadin.Flow.Portlets) {
    window.Vaadin.Flow["Portlets"] = {};
}
if (!window.Vaadin.Flow.Portlets.$0) {
    if (portlet) {
        portlet.register($0).then(function (hub) {
            window.Vaadin.Flow.Portlets[$0] = hub;
            hub.addEventListener('portlet.onStateChange', function () {
                $1.server.smash(hub)
            });
        });
    }
}

The event listener for portlet.onStateChange is required else any action will result in a missing event handler warning. In the sample case it would just send the hub json to a server ClientCallable method.

and now on a button click we could use the window state chage as


var hub = window.Vaadin.Flow.Portlets.$0;
hub.setRenderState({
    'parameters': {},
    'portletMode': 'VIEW',
    'windowState': hub.windowStates[1]
});
const poller = () => {
    if (hub.isInProgress()) {
        setTimeout(poller, 10);
    } else {
        location.reload();
    }
};
poller();

@caalador caalador moved this from In progress to Iteration Reviews in OLD Vaadin Flow ongoing work (Vaadin 10+) Oct 3, 2019
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Iteration Reviews to Done - pending release Oct 11, 2019
@caalador caalador added this to the 1.0.0.alpha1 milestone Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

No branches or pull requests

3 participants