Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

inject bean into bean with producer  RSS feed

 
Piter Smith
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure that I have my @Inject backwards or something. The idea is for a Messages bean to "have-a" MessageBean through @Inject. Part of the problem seems to revolve around how to get a javax.mail.Message instance from Messages to MessageBean, because Messages takes a List of Message's.

I'm working through the oracle docs, but get a bit lost.

This should be done through a Producer class so that CDI can find the Message?

Perhaps my basic approach is wrong here. As each Message is traversed through the DataModel I want to perform further processing on that particular object and include the results in the DataModel -- MessageBean.getUrl() is one such method. However, perhaps the EL is just wrong-headed?



Messages.java




MessageBean.java



glassfish:

INFO: SingletonNNTP..only once...
INFO: NNTP.loadMessages...
INFO: SingletonNNTP.connect..
INFO: SingletonNNTP.setIndex..2,555
INFO: SingletonNNTP.page..2,565
INFO: SingletonNNTP.setIndex..2,555
INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/NNTPjsf'
INFO: WEB0671: Loading application [NNTPjsf] at [/NNTPjsf]
SEVERE: Exception while loading the app
INFO: SingletonNNTP..only once...
INFO: NNTP.loadMessages...
SEVERE: Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [Message] with qualifiers [@Default] at injection point [[field] @Inject private net.bounceme.dur.beans.MessageBean.message]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Message] with qualifiers [@Default] at injection point [[field] @Inject private net.bounceme.dur.beans.MessageBean.message]
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:274)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:243)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:106)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:126)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:345)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:330)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:199)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:128)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:313)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)


 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure that this question relates at all to JavaServer Faces. JSF does support injection - in fact, Inversion of Control is an essential part of JSF. But the usual means of injection in JSF ManagedBeans is via the ManagedProperty annotation or its XML equivalent, and the ManagedProperty takes an EL expression that tells what is going to be injected.

In JSF - and in most IoC systems - injection is not a dynamic thing. In particular, in JSF, the Managed Properties are injected after the bean is constructed and before the PostConstruct method (if any) is invoked. Thereafter, no further injection is done for the life of that particular bean instance. So essentially, the injected items are immutable. You can inject a list of Messages, for example, and the messages in that list might change, but the same list will always be used.

 
Piter Smith
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:But the usual means of injection in JSF ManagedBeans is via the ManagedProperty annotation or its XML equivalent, and the ManagedProperty takes an EL expression that tells what is going to be injected.



Does @ManagedProperty work with CDI?


java.net
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think my current enviroment supports CDI, so I haven't experimented, but in general, CDI is just the generic standard for various features that have (for historical reasons) JSF-specific annotation support. Your main problem with the @Inject was that you weren't specifying what to inject.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!