I was making some test with my JSF-app and when I tried it in the same web-browser on different tabs, in all tabs the last session was present.
How can I prevent this?
That isn't possible without hacking/changing the browser. But this really shouldn't matter. If that causes unintuitive behaviour in your JSF application (e.g. data of one tab is been redisplayed in another tab), then you were apparently storing view scoped data in session scoped beans. You should store view scoped data in view scoped beans instead.
Or if it is purely intended for testing purposes (i.e. you just wanted to test physically separate user sessions), then you should use physically separate browsers. E.g. one Firefox and one Chrome.
Or if you absolutely need to have "one user session per tab/window", then store the logged-in user in a view scoped bean instead of a session scoped bean and exclusively use ajax postbacks to navigate through pages (SPA - Single Page Application).
See also:
How to choose the right bean scope?
How do servlets work? Instantiation, sessions, shared variables and multithreading
How to ajax-refresh dynamic include content by navigation menu? (JSF SPA)
Related
I'm using Vaadin 8 in a Spring Boot application and have a view scoped View.
I'm using view scope because I want to have a new instance each time I navigate to the view, and more importantly I don't want the view (and its data) to remain in memory when the user has navigated away from the view.
However, I would like to be able to navigate to this view from within the view itself, with different parameters. In that case I don't want the view instance to be recreated (and its data to be reloaded). Is there a way to do that? Maybe with a custom Spring scope?
when is a view scope in an Domino XPage application lost by timeout, when the page is not accessed anymore? Is there a timeout? Or are they lost not until the session is closed (because of a logout or of the timeout)?
I know, that there is the server page persistence configuration in the Xsp Properties. But when is the scope lost, if you do nothing in the browser? You don't work in other tabs, so that there are not too much pages. (Is there an event listener for that, that allows me to print this out?)
Thanks in advance
AFAIK a viewScope object cannot live longer than the user's session. In addition it is bound to the current page's rendering for a given user.
This basically means that there are three options to kill a viewScope object:
move on to a different page
ask for a new rendition of the same page (like re-entering the same URL etc,; in fact this is the same as #1)
terminate the session by logging out, closing the browser etc.
You might want to try youself by building some test pages with a computed field bound to a viewScope variable; make sure that the variable is set through a button or the likes. Another option is to implement the Xpages debug toolbar available from openNTF.
A very simple explanation of all 4 scopes can be found here: http://www-10.lotus.com/ldd/ddwiki.nsf/dx/xpages-scoped-variables.htm, but you might be aware of that already.
I am looking for the best way to handle a session-persistant search form in a "shopping cart" like web application using the Spring MVC Framework.
I want to be able to navigate back to this search page, with last filters already set, from any other page in the application. This is not a master detail search results page, only a form with filters on a table of elements displayed underneath.
I can store my search filters in the user session, but what about multi-tabs navigation and browser back button handling ?
I also considered using Spring WebFlow to adress this.
Any suggestions ?
That sounds like a good job for the conversation scope of Spring WebFlow. Objects which are stored in this scope are saved until the current flow is terminated (or by timeout). The usual way to use it in your case would be to create a new flow/conversation when the user starts browsing the webpage and saves the search parameters in the conversation scope. When going back to the search page later, the parameters are retrieved from this scope (if there are available).
The conversation scope solves the multi-tabs problem and avoid to have to send back to the server every time the data (as you would have to do if you only use the request scope).
I am new to JSP/Servlets/MVC and am writing a JSP page (using Servlets and MVC pattern) that displays information about recipies, and want the ability for users to "comment" on it too.
So for the Servlet, on doGet(), it grabs all the required info into a Model POJO and forwards the request on to a JSP View for rendering. That is working just fine.
I'd like the "comment" part to be a separate JSP, so on the RecipeView.jsp I can use to separate these views out. So I've made that, but am now a little stuck. The form in the CommentOnRecipe.jsp posts to a CommentAction servlet that handles the recording of the comment just fine. So when I reload the Recipe page, I can see the comment I just made.
I'd like to:
Reload the page automatically after commenting (no AJAX for now)
Block the user from making more than one comment on each Recipe over a 1 day timeframe (via a Cookie). So I store a cookie indicating the product ID whenever the user makes a comment, so we can check this later? How would it work in a MVC context?
Show a message to the user that they have already commented on the Recipe when they visit one
which they have commented on
I'm confused about using beans/including JSPs etc on how to achieve this.
I know in ASP.NET land, it would be a UseControl that I would place on a page, or in ASP.NET MVC, it would be a PartialView of some sort. I'm just confused with the way this works in a JSP/Servlets/MVC context.
you can use response.sendRedirect() or forward APIs in javax.servlet to redirect to a new page or refresh the same page (redirect to the same page/path so that the beans/data gets refreshed)
about restricting to one comment per day - yes you can use cookie but the problem is that user might use another browser type (chrome, FF, Safari) and will be able to make multiple comments.
Ideally you should store the lastCommentTime in the model/persistent store and tie it to the user information - this way your model object can expose an API that checks the last comment time and returns true/false depending on whether user can comment or not.
You can use this API in your servlet/JSP to show/hide the comment button, for example and also show a message
I'm writing an application in JSF 1.2 that has a session in a backing bean.
The biggest stability issue happens when the user refreshes the page (by pressing F5) or uses the backward arrow in the browser to go back.
I would like some 'smart' (knowledgeable) way to overcome this.
The most common exception I get is that after a refresh, the user will try to continue using the application and would get a:
java.lang.IllegalStateException - duplicate Id for a component
in the browser.
Thanks!
Don't bind physically different components by binding to one and same bean property.
If you want a smart (knowledgeable) way to overcome this, add seam to your jsf application. They have solved the backbutton problems in JSF