Hello everyone,
first of all I am a beginner with JSF and I still have some troubles understanding everything.
I have a Windows deamon programmed that will transmit several sensor states from our house via JMS (from JBoss) for my web application. The communication and the deamon works good.
Now I want to display those information on my web page with Rich- and Primefaces.
What I have done:
- IncomingEventListener.java implements MessageListener
- in the faces-config.xml I put the incomingEventListener as an application bean
- Inside the constructor of the incomingEventBean is tried to init the jms listener, but unfortunately the constructor isn't called when I deplyed the project and open the web browser on that page.
I understood the application wide beans so, that it will be called once when the application starts and somebody opens the first time the application.
My little work-around was to display a variable from this bean so it had to call the constructor first. What I am doing wrong?
The other idea was to put the init process into a contextListener, but from that class I can not go to any other beans via FacesContext.
The next problem is inside the onMessage-method inside the incomingEventListener. Based on the message I have to put some values in some other application beans.
This bean called ActualStateBean and it is also inside the faces-config.xml as application bean. In this class I have a refresh() method I need to call from the
incomingEventListener. So I tried :
FacesContext fc = FacesContext.getCurrentInstance();
ExpressionFactory expressionFactory = fc.getApplication().getExpressionFactory();
ELContext elContext = fc.getELContext();
return (ActualStateBean)expressionFactory.createValueExpression(elContext, "#{actualStateBean}", ActualStateBean.class).getValue(elContext);
But I get a NullPointer because FacesContext is null. I understood that problem occures when I try to get the FacesContext instance inside a class that
is not inside the faces-config.xml.
My work-around in the moment is to change the variables I have to modify inside the actualStateBean to public static. That works but I don't like this
solution.
Hopefully I didn't forget anything and I hope I am on the right track.
Many greetings and have a nice weekend,
Hauke