0

i am learning JMS, i want to apply it with JSF, i created 2 managed beans the producer which sends the message and the consumer, i made a MDB which implements the messagelistner and has onMessage method, the JMS provider is Wildfly 8, i can send the message from JSF by the producer and the MDB receive it, i want to make the MDB access the consumer managed bean and set the message then update it in the JSF again, i tried @Managedproberty and @EJB but i get null, also the requestContext and faceContext is null in the MDB, i am still beginner at EJB so i miss many things, my question how can i access the managed bean from EJB generally and MDB specially, i know i can use other technologies to do that like prime push or even web sockets but i want to learn the JSM first. this is the MDB code

package boddooo.jms;

import java.io.Serializable;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.primefaces.context.RequestContext;

@MessageDriven(
    activationConfig = { @ActivationConfigProperty(
            propertyName = "destination", propertyValue = "jms/queue/boddooo"), @ActivationConfigProperty(
            propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    }, 
    mappedName = "jms/queue/boddooo")

public class mdb implements Serializable, MessageListener {

private static final long serialVersionUID = 1L;

TextMessage tm;

@Override
public void onMessage(Message message) {
    if(RequestContext.getCurrentInstance()!=null){
        RequestContext fc=RequestContext.getCurrentInstance();
        consumer c=(consumer)fc.getAttributes().get("consumer");
        tm = (TextMessage) message;
        try {
            c.setMsg(tm.getText());
        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

}
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Mohamed
  • 337
  • 3
  • 18
  • An upvote within a few minutes... fishy... The answer to your question is: you can't directly. The solution is to use 'push' and have the client retrieve the results. – Kukeltje Sep 01 '15 at 12:37
  • this means the MDB or EJB does not know anything about faces? – Mohamed Sep 01 '15 at 13:08
  • 'Nothing' is to strong, but not in the context of a request (hence FacesContext and RequestContext being null) – Kukeltje Sep 01 '15 at 13:12
  • possible duplicate of [EJB Schedule task with access to JSF Managed Beans](http://stackoverflow.com/questions/15076409/ejb-schedule-task-with-access-to-jsf-managed-beans) – kolossus Sep 02 '15 at 02:49
  • @kolossus could you please give me help to this question, it is related http://stackoverflow.com/q/32336462/5288242 – Mohamed Sep 02 '15 at 07:09
  • 1
    Did you read the answer in the link I posted @Mohamed? – kolossus Sep 02 '15 at 14:19

0 Answers0