Max Korn
Max Korn

Reputation: 275

How to use a @Produces List both in JSF view and CDI Beans

I have a CDI based Web application which displays in a dataTable a list of Tickets that is produced in my ProducerBean:

@Produces
@Named
public List<Tickets> getTickets() {     
   return tickets;
}

<h:dataTable var="tickets" value="#{tickets}" >
    . . . 
</h:dataTable>

This works perfectly, however I need to use this List of Tickets ("tickets") beyond JSF EL.

Another CDI Bean which is referenced in the same page uses:

@Inject
private List <Tickets> tickets;

However the list of tickets injected is empty. I still can query again the Tickets via JPA, however I'd like to reuse that List I have produced. Is it possible to do it ?
Thanks a lot

Upvotes: 1

Views: 385

Answers (1)

kostja
kostja

Reputation: 61578

I suppose that at injection time, the tickets field of the first bean is empty. The injection is performed at bean instantiation, so make sure you instantiate the tickets field properly inside the @PostConstruct method of the first bean.

Upvotes: 1

Related Questions