JSF - session scoped bean shared by browsers on different machines - java

We have a search form where the filter is bound to a property on a managed bean (session scope). It's not component binding, its property binding like <h:inputText value="#{searchBean.filter}"/>.
Submitted data from different machines (different sessions, then) is getting mixed. You search "john", and get "mary" just because the guy beside you have just searched "mary". The value of your searchBean.filter is getting his submitted data instead of yours.
I've already googled around a lot and found no solution, just an ocurrence of the same problem.
Have anybody faced this issue already? Any clues?
Thanks!

This can have two causes:
The bean is actually in application scope.
The property in question is declared static.
To fix 1), just ensure that it's in session scope.
To fix 2), just remove the illegal modifier.

Solved! Finally. Thanks guys, for your attention!
It was something like what Balus guessed at the first time. It was a static hidden in a dark corner. I had really double, triple checked everything looking for statics, but -- don't ask me why -- someone created a second bean (Foo) which was holding a static reference for SearchBean.
In the JSP, there was an action="#{foo.search}" instead of searchBean.search. Class Foo had a method with the same name as in SearchBean, that was doing no more than a searchBean.search();.
I think pressure for fixing this bug for yesterday didn't allow me to see this trap in the JSP.

Related

SessionMap does not save the objects JSF

In my application the objects put into sessionMap doesn't stored. I can access it in the same object where I have done the put operation, but when I want to do it from another bean, the object doesn't exist. I put the objects into the session in the following way:
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put( "myKey", myObject );
This is the first time that happens. In another apps I can access the objects stored in the sessionMap.
Best Regards
DrakoRod
Thanks for your help, finally I resolved the problem, really a don't saw exactly what's was. I explain what I did.
First. My project was in a normal template with this frameworks: JSF 2, primefaces, Spring, Hibernate and log4j. So, all was going well. I added a new template to project and happened the problem with session.
But I just copy/paste code in menu, so I decided write tag by menu's tag and vuala! everything worked.
How I say, I don't saw what's was the problem, but I solved it.

prototype spring bean with global static variable

I have a question that i have a spring-MVC based project. In which there is a class containing all static variable which is accessible by all users. All Bean are singleton, which creates problems when multiple users access application: the last user to modify the static variable at the same time a previous user is performing their task. So after last user comes the previous user's data, which overlaps with the data from the last user which creates conflict in the report. I also user prototype bean, but I didn't find any solutions because of the static variable. So anyone have solution related to this problem? Thanks.
First: use db, and save data there. If you restart your program all changes by users will be discarded.
Second: you tagged it corectly, since it is a question of concurency: make synchronization block, keep version, upon entrering synchronization block check if change is changing the latest version or previous one:
if you change latest commit - ok, if it's not: handle exception.
third: this smells bad desing. Are you sure you need all users MODIFY one parameter? Do you keep records of who and how modified it? Singletons are primarly used as read-only immutable objects that share information across whole application.
And forth: please, do not use static mutable variables. Seriously.

XPages: NotSerializableException on DateTime

I'm kind of desperate. We have a lot of code, and we also have a lot of variables of which many are inside viewScope and other HashMaps. Every now and then we get the error that some DateTime object cannot be Serialized. I understand the why, no problem there. But which variable? Which element of the HashMap? Since Serialization happens automatically, out of my control, the problem could be anywhere. It could be a DateTime value the code puts into a viewScope variable (I think I checked them all), it could be my own beans' HashMaps, and it could even be lines with column values from a view. I just don't know...
Can anyone point me into the right direction to find out where that #$#%#! exception really occurs? For instance: can the stack trace be more informing about which HashMap it found the problem in, and maybe even which key??
#$#%#! - read: elusive...
One option would be to add a PhaseListener to your application that, in Render Response phase, iterates through all scopes and outputs the key and the output of getClass() for the value. The code could also do the same for the hash maps in the beans.
There are various examples of PhaseListeners on XSnippets.

JSF One Session Per User

I just started learning with JSF and I'm wondering about this issue.
I have 16 Checkboxes. When I open the Page and my Brother is opening it too it seems like we have the same session. When I click one of the checkboxes it is checked on my brothers browser too.
The selected checkboxes are saved in a private ArrayList<String> selectedBoes = new ArrayList<String>();
My ManagedBean ist SessionScoped.
Why is this happening and how to avoid it?
My brothers session ID is cdbbb126e96060ddb924b9d5e591. Mine is cd9a5c4180bd9dfef0ec8db2ac4d
Then the only possible cause is that you're actually not storing them in the session scope. The symptoms indicate that you're either storing them in the application scope, or even that you declared it static (and thus the code in the question does not represent the real code at all; the code in your comments indicate that also less or more, you used a different property name, apparently you attempted to type it from top of head, you should not do that, you should copypaste the real code).
Note that when you're using CDI's #Named instead of JSF's #ManagedBean, then it would default to the application scope, unless otherwise specified with a javax.enterprise.context scope annotation. So if you're using JSF's own javax.faces.bean.SessionScoped annotation, which is not supported by CDI, then it would still be in the application scope.

Accessing a bean with a dot(.) in its ID

In a flow definition, I am trying to access a bean that has a dot in its ID
(example: <evaluate expression="bus.MyServiceFacade.someAction()" />
However, it does not work. SWF tries to find a bean "bus" instead.
Initially, I got over it by using a helper bean to load the required bean, but the solution is inelegant and uncomfortable. The use of alias'es is also out of the question since the beans are part of a large system and I cannot tamper with them.
In a nutshell, none of the solution allowed me to refernce the bean directly by using its original name. Is that even possible in the current SWF release?
I was able to do this by using both the bean accessor (#) symbol and single-quotes around the name of the bean.
Using your example: #{#'bus.MyServiceFacade'.someAction()}
This is a restriction of the EL parser (generally either OGNL or jboss-el for Spring Web Flow). EL uses dot notation for parsing the navigation chain,causing the initial behavior you describe (attempting to find the "bus" bean).
Try:
['bus.MyServiceFacade'].someAction()
or
'bus.MyServiceFacade'.someAction()
This may work, or it may not...but similar things are used in the Expression Language for JSPs.
In my experience, anything with a getter method can be accessed via dot notation. In your example, whatever object is being represented by the bus bean needs to have a getServiceFacade method and that the object returned by getServiceFacade would need to have a getSomeAction method.

Categories

Resources