问题
My code:
<p:socket channel="/allposts/#{uview.user.uid}">
<p:ajax event="message" async="true" listener="#{uview.go}" update="xout"/>
</p:socket>
#1. uview refers to a view scoped bean. Everything ,including update, works except listener method. Listener method is never invoked. Even if I change the value of listener to a method which is not existing, it isn't reporting any error. Any idea why it isn't working?
Another thing I noticed in the following code snippet[involving dynamic id]:
<p:socket channel="/allposts/#{uview.user.uid}">
<p:ajax event="message" async="true" listener="#{uview.go}" update="#{uview.user.uid}"/>
</p:socket>
Here, it reports error stating that it can't find the id with the specified id[ shows the id in error message]. Even if there's a element with that id, it can't find that. It's certainly not naming container reference problem.
Is it happening because Primeface sockets are initialized even before page[dynamic part] is rendered by JSF & that's why it can't find the dynamic id???
#2. As I've understood from Pimeface Demo page, updating an element with dynamic id is required to implement a chat application in JSF. Am I going wrong here in implementing primeface socket? Are there other ways to implement it more elegantly?
回答1:
uview refers to a view scoped bean. Everything ,including update, works except listener method. Listener method is never invoked. Even if I change the value of listener to a method which is not existing, it isn't reporting any error. Any idea why it isn't working?
It is a bug. I found the following workaround: the code like this
<p:socket channel="/channel">
<p:ajax event="message"
listener="#{controller.yourListenerMethod}"
update=":form:table" />
</p:socket>
replace with:
<p:socket onMessage="handleMessage" channel="/channel" />
<script type="text/javascript">
function handleMessage(data) {
updateWidgets();
}
</script>
<p:remoteCommand name="updateWidgets"
actionListener="#{controller.yourListenerMethod}"
update=":form:table" />
来源:https://stackoverflow.com/questions/15391190/how-primefaces-socket-works