-
1. Re: how to inject a list?
edewit Aug 2, 2013 12:46 PM (in response to magick93)Hi Anton,
Do you mean how to use them in errai-ui? If so you can use an ListWidget or create an Provider to inject the list
Cheers,
Erik Jan
-
2. Re: how to inject a list?
magick93 Aug 2, 2013 1:01 PM (in response to edewit)Hi Erik
The data in the List<Indicator> is used in the UI, however, the data in the list is displayed differently in different components.
I am already using the ListWidget now to display the items on the page.
However, there are other components that need this data.
For example, we have a component that shows in a modal window, and uses data from the List<Indicator>. We either have to explicity pass this list from the page to the component, or again call the service.
So, I am looking for a way to:
Call the service once, and retrive the List<Indicator>
And have this value available for client components without being tightly coupled.
-
3. Re: how to inject a list?
jfuerth Aug 2, 2013 1:29 PM (in response to magick93)Have you tried an application-scoped producer? Maybe something like this:
@ApplicationScoped public class IndicatorBeanProvider { @Produces private List<Indicator> indicatorList; @AfterInitialization private void fetchIndicatorList() { indicatorService.call(...callbacks...).getIndicators(); } }
and in the callback from the RPC, assign the response value to indicatorList. Then wherever you @Inject List<Indicator>, the CDI context should inject the same list that the producer field references.
I think this should work for your use case. It would not work if you required a different list of indicators to be injected at different injection points, although you could possibly use CDI qualifiers to solve that problem.
-Jonathan
-
4. Re: how to inject a list?
magick93 Aug 2, 2013 3:07 PM (in response to jfuerth)Thank you Jonathan!
That tip signifcantly cleaned up our code!