vaadin / vaadin/framework

OSGi DS @Reference not working in OSGi UI

Open
#10,200 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
1.8k
Forks
717
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Hello,

I'm using 8.1.5 and want to create an OSGi UI (not portlet). Unfortunately in the UI there seems to be the same problem as there was in portlet when using
@Reference to inject OSGi DS services into the UI

When the UI bundle is activated the reference to the service gets correctly injected in the UI instance, unfortunately when the UI is displayed, the UIProvider seems to create a new instance of the UI and thus all references are lost.

Here the flow ...

  1. the service is being injected

setting testService = test.impl.TestServiceImpl@8508b80 com.example.myapplication.MyUI@79405478

  1. now the bundle is activated

in activate test.impl.TestServiceImpl@8508b80 com.example.myapplication.MyUI@79405478

all this happens on the same UI instance

  1. when displaying the UI in the browser, the init method gets called and we get a new UI instance
    karaf@root()> in init ...null com.example.myapplication.MyUI@541d9c7

@PreserveOnRefresh doesn't seem to work because I suppose it only acts on the refresh not on the first init.

OSGi injects the service before the new UI instance gets actually created by the UIProvider.

In portlets the solution was to support the ServiceScope.PROTOTYPE in the OsgiUiProvider.

Regards,

Alex

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the OsgiUiProvider and UIProvider flow described in the report, then compare it with the portlet solution involving ServiceScope.PROTOTYPE. Reproduce the first browser display and verify whether the UI instance differs from the one receiving @Reference injection. Done means the OSGi service remains available when the UI is initialized.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.