I'm running the latest PrimeFaces showcase demo on GlassFish 4 and I'm running into the problem where every time the socket.connect("/user") is called, "/user" is simply being appended to the exiting URL.
requestContext.execute("PF('subscriber').connect('/" + username + "')");
Maybe the disconnect method is not working correctly?
The outcome is there are an increasing number of path segments so they don't get properly mapped to the path variables on the endpoint class.
A page refresh before making the connection works.
I know this came up in one similar post but I'm not allowed to comment.
Primefaces Push - What are the methods in <p:socket/> client widget
Thanks for any help :)
Looks like this was a defect that has been fixed now.
https://github.com/primefaces/primefaces/issues/1132
Related
First of all sorry if this question has been already asked somewhere, but after a few hours on google I still can't find an answer.
I am pretty new in portlet development, (but we have a shortage of developers and I have to work with it time to time), so the solution might be something trivial, but I really don't have enough experience with it.
The problem is I have two portlets on a page and I try to let one of them know about changes in the other. For this I use IPC. In the first one I have a Liferay.fire function:
function fire(key,value){
Liferay.fire(
'category',{
id: key,
name: value
}
);
}
In the other I have a Liferay.on('category',function(category){...}) function with an ajax call inside and some rendering methods.
Now if I visit the mentioned page and click on the corresponding buttons, at first everything works just fine. However, if I navigate from this page and come back, the listener will run two times. Navigating again -> three times. And so on... But if I reload the page (with F5 or CTRL+F5), it starts over, so until further navigation the listener runs only once.
The other strange thing is no matter how many times the function runs, the input parameters are all the same for each.
For example, if I have left the page and went back to it 3 times and last time I chose the category with 'id=1', then the function will run 3 times with 'id=1'. Now if I choose 'id=2' it will run 3 times with 'id=2'.
If anyone has any idea I would be really grateful as I am stuck for almost a day now.
Thank you very much in advance and please let me know if you need any further info.
the problem you're having is caused by the global Liferay.on listeners that are being created but never removed.
In Liferay Portal 7.x, SPA navigation is enabled by default. This means that when you are navigating, the page isn't being completely refreshed, but simply updated with new data coming from the server.
In a traditional navigation scenario, every page refresh resets everything, so you don't have to be so careful about everything that's left behind. In an SPA scenario, however, global listeners such as Liferay.on or Liferay.after or body delegates can become problematic. Every time you're executing that code, you're adding yet another listener to the globally persisted Liferay object. The result is the observed multiple invocations of those listeners.
To fix it, you simply need to listen to the navigation event in order to detach your listeners like this:
var onCategory = function(event) {...};
var clearPortletHandlers = function(event) {
if (event.portletId === '<%= portletDisplay.getRootPortletId() %>') {
Liferay.detach('onCategoryHandler', onCategory);
Liferay.detach('destroyPortlet', clearPortletHandlers);
}
};
Liferay.on('category', onCategory);
Liferay.on('destroyPortlet', clearPortletHandlers);
With plain Jsf postback to same page (with return null in method) from commandLink, I am ending up with two duplicate entries in browser history. One entry with url with ending # and one with url without ending #. Please help if you have any idea why this could happen and advice avoiding it.
I am assuming this is not a standard behavior with JSF postback request. Please help confirming it.
Also please suggest where I could be going wrong. I am using Myfaces 2.1
Also any pointer to debug this scenario is very much appreciated.
Thanks very much for your help.
I have found out my issue. As I had expected, it is not the issue with JSF as such. I have commandLinks with onclick method, for disabling all the hyperLink controls to prevent repeated submits. That method is also setting location.href = "#" before returning true, and this was the cause of double entries in browser back history. Posting the answer, hoping it will help others with same scenarios. Thanks all for viewing this question.
I'm using JSF1.2, Tomcat 6.0, RichFaces 3.3.3, and Java 6u31.
I do an action in the managed bean, and show a message to the user. That's OK.
After that, I do another action in managed, and then the messages doesn't work anymore until I refresh the page.
I can assure you that the problem isn't in the managed bean, because I just removed all the method impl, leaving it empty, and the bug still happens.
So, the problem is something in the xhtml pages. I tried to put an a4j:status, but it doenst show any error.
So, I see myself without hope. I will not post all the code here, because it's too big and complex.
I wonder if one of you ever seen something like this, or if you have one guess of whats happening. I can edit the question adding any info you want.
I solve this problem.
I has a onupload in the rich:fileupload.
I just remove it, and add a a4j:support, like this:
<a4j:support event="onupload" oncomplete="foo()" />
That's it. I just don't understand why it works that way, and doesnt in the old way.
BTW, thanks.
I'm using the inputRichText component for composing HTML-formatted messages in a system I'm working on.
I've encountered a problem, however. It seems the session times out, even when the user is working in the editor.
I tried setting the session timeout parameter in web.xml to 1 minute and started typing in the editor. After 1 minute the "User session expired" dialog box appeared. Is there any way to make the rich text editor component keep the session alive? It's pretty annoying to work on something for a while only to loose it to a session time out, event though you haven't been inactive.
This is the code I use to display the component in the page:
<ice:inputRichText height="250" toolbar="MyToolbar" customConfigPath="/FCKconfig.js" id="messageBody" value="#{bean.messageBody}" language="sv" saveOnSubmit="true" />
Thanks!
Edit:
I solved it using a periodic JavaScript calling into a servlet implementing the stuff outlined in this IceFaces JIRA report
If there's a better way, please let me know :)
I solved it using a periodic JavaScript calling into a servlet implementing the stuff outlined in this IceFaces JIRA report.
It basically allows a servlet to "touch" the session and hence keep it alive.
If there's a better way, please let me know :)
I have one page that does something and when the user clicks a button, the user is redirected to another page and a message is displayed. Here is my code:
public String confirm() {
FacesContext context = FacesContext.getCurrentInstance();
Flash flash = context.getExternalContext().getFlash();
flash.setKeepMessages(true);
FacesMessage msg = new FacesMessage("Succesful", "Release is confirmed!");
context.addMessage(null, msg);
return "/prot/expert/releases?faces-redirect=true";
}
I use a p:growl component which displays my message on the "releases" page. So far so good.
But then on any subsequent page that has p:growl (or if I go to another page and go back) the message is displayed again and again and I can't kill it.
I tried something like:
<c:set target="#{flash}" property="keepMessages" value="false" />
on the page that has the p:growl, I tried clearing the flash from the backing bean etc.
The message is retained and displayed all over again. If I remove flash.setKeepMessages(true); from the code above then nothing is displayed.
What am I doing wrong?
I did get the exact same problem on JBoss AS 6 with both Mojarra 2.0.3 and Mojarra 2.1.1. The flash should survive only one redirect, but in practice it not always does.
In an action method I have basically the same code:
// [add global faces message]
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
return "/someView.xhtml?faces-redirect=true";
I've been seeing three symptoms of the problem:
After doing a postback on someView, the flash faces message keeps being displayed
After a clean request to a completely different page, the face message is also displayed
After going again through the code that adds the faces message, you'll get two of the same messages on someView
Issue 2 can be explained by realizing that the flash scope is cookie based (at least in Mojarra). Relatively few people seem to understand the inherent problem with that. I've found this related question, but it has no answers: Is Flash scope free of race conditions?
Also, when trying to reproduce the problem I've got approximately a 2/3 chance of actually reproducing it. Sometimes it indeed only survives a single redirect, sometimes it's gone after a few refreshes (time based or so?) and sometimes it just sticks around and the only way to get rid of it is restarting my server(!).
Maybe I'm doing something wrong somewhere?
Observing the cookies being set, I noticed the followed:
After initially triggering the action that does the redirect:
POST Response
Set-Cookie csfcfc=_50Xfr
GET Response
Set-Cookie csfcfc=50Xfn_51Xfn
The thing to notice here is that the response from the GET request for the redirect again sets a cookie. You want think that for a flash scope the cookie would need to be deleted here.
If I submit a form on the view towards I'm redirected, the following happens:
POST Response
Set-Cookie csfcfc=_50Xfn
The message is now gone.
However, when I submit the form once more, the following happens:
POST Response
Set-Cookie csfcfc=_52Xfn
And, the message is back :(
If I again submit the form:
POST Response
There is no more Set-Cookie header and the message in once again gone. If I continue submitting the form, the last cookie (csfcfc=_52Xfn) keeps being send to the server, but there are no more new cookies being set and no messages are displayed.
Edit:
During debugging I came across a critical section in ELFlash.java (Mojarra 2.0.3):
void saveAllMessages(FacesContext context) {
// take no action on the GET that comes after a REDIRECT
Map<Object, Object> contextMap = context.getAttributes();
PreviousNextFlashInfoManager flashManager;
if (null == (flashManager = getCurrentFlashManager(contextMap, true))) {
return;
}
if (flashManager.getPreviousRequestFlashInfo().isIsRedirect()) {
return;
}
}
During the context of the GET request following the redirect, one would suppose isIsRedirect would return true, but it returned false. This could be a local problem, that I'm going to investigate further.
Interesting to note is perhaps that the cookie values actually have some meaning, according to the following:
FirstTimeThru("f"),
SecondTimeThru("s"),
IsRedirect("r"),
IsNormal("n");
So the first cookie (_50Xfr), is a FirstTimeThru and a IsRedirect.
Your concrete problem is caused by a bug in older Mojarra versions, specifically issue 1751. There have however been many issue reports for the flash scope afterwards. The flash scope is in older Mojarra versions known for the following major problems:
issue 1751 - Flash scoped messages lives longer than next request - fixed in 2.0.7 / 2.1.4
issue 2126 - Flash cookie enables data exploits - fixed in 2.1.24 / 2.2.1
issue 2136 - Flash cookie not available when redirected to different path - fixed in 2.1.14 / 2.2.0
issue 2902 - Flash cookie uses wrong path for applications on root - fixed in 2.1.24 / 2.2.1
issue 2955 - Flash creates sometimes version1 cookies which fails in IE<=10 - fixed in 2.1.25 / 2.2.2
issue 2973 - Flash causes NPE on stale cookies after a session expire - fixed in 2.1.25 / 2.2.2
issue 2862 - Flash cookie not cleared when stale - fixed in 2.1.27 / 2.2.5
All in all, concluded can be that you'd need to upgrade to a minimum of Mojarra 2.1.27 / 2.2.5 (due date 2 january 2014) in order to get rid of all those problems.
Try setting property redisplay to false:
<p:growl redisplay="false"/>