HI,
How to retain the current state of the application with all the opened tabs and loaded grid when user does browser refresh or f5 in GXT using MVC pattern?
Regards,
Srini
One approach is to set browser cookies so that browser state can be restored at a later point.
Construct the grid/tab panel
Set a cookie with the current paging settings or open tabs
When the paging settings change or when tabs are opened/closed, update the cookie
Now that you're setting cookies, update step 1 so that you construct the grid/tab panel using settings you read from the user's cookies. Of course, if no cookies are set, use the default settings (grids start on page 1; no tabs open in the tab panel).
If you are using a fairly strict separation of concerns in your MVC pattern, the setting and updating of cookies should occur in the controller layer. The cookies themselves are another source of model data, and the view (UI widgets) need not understand why tabs are open or why the grid starts on page 3.
Related
We're using one of the new responsive themes of PrimeFaces 8 (Mirage if that matters) I've implemented a dynamic menu to create the menu of my page. Depending on several parameters, the landing page can be different. Example:
Suppose there's a communications environment in which the menu items are
Documents (opens by default)
E-mail
Pictures
When arriving in the communications environment, the application checks whether there are new e-mails. If so, the user won't arrive on the "Documents" page but on the "E-mails" page.
The theme uses cookies to restore the menu state based on what the user has chosen previously. So suppose last time (s)he has chosen "Pictures", the result now is that the menu item "Pictures" is marked as active-menuitem but the displayed page is "E-mail".
I was already able to clear the cookies so that no menu item is active, but now I'm trying to activate the correct menu item. I got most successful by calling
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('li'));
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('ul').closest('li'));
but since the page is rebuild using ajax, this only works once 🤨. Using the build-in .active-menuitem doesn't work so that's why I introduced .custom-active-menuitem that I set in Java code:
DefaultMenuItem.builder()
.value("E-mail")
.icon("fa fa-letter")
.command("#{communicationBean.openEmailPage()}")
.styleClass("custom-active-menuitem") // or something else to mark this item active
.process("#this")
.update(":page");
So now I'm puzzled. Can someone please get me in the correct direction? How can I make the theme show the menu item I choose as active one?
I have been going crazy about resetting some validation error on one of my jsp pages. This is a project inherited from people I cannot reach anymore (dead or unavailable). I have a jsp page with lots of custom taglibs where further pages are added as tabs and the parent page has action buttons to open things like forms. There is a validation error and some configuration parameter being set/modified both in the tabs section and the parent page. But the interesting thing is that I can see the heavy use of pageContext.setAttribute(), session.setAttribute() and pageContext.getSession().setAttribute(). If my initial knowledge is right, pageContext is quite heavily used in servlet-based implementations. but how different things would be if I use those following three on my JSp pages to set attributes?
** Example Scenario (my problem): **
I have some attributes set in the parent page, which are also being set/modifed in the tabs page (embedded in the parent page). I want to remove them such that if there is a validation error, I will simply remove what I have in the tabs page i.e. next time the page will simply load those attributes from the parent page. Do I use pageContext.setAttribute() in the tabs page, but use pageContext.getSession().setAttribute() in the parent page?
KR,
Page scope
When we put in our JSP page, scope is available only for the JSP page that put it.
This is the default scope, so is the same to call pageContext.setAttribute("", "", PageContext.PAGE_SCOPE); same as pageContext.setAttribute("", "");
Session scope
session.setAttribute() and pageContext.getSession().setAttribute() both are same.
What you put on your session scope is available across all requests on the same user session.
Is the same to call pageContext.setAttribute("", "", PageContext.SESSION_SCOPE); same as session.setAttribute("", "");
In my web application
1.1I have to close the session when the user abruptly close the browser.
1.2. When the user tries 'open in a new tab' - The user should be forwarded to the 'login page' in the new tab
I am planning to use JAVASCRIPT and AJAX to implement this in JSPX.
Can any one share any sample code to implement he above as I am new to javascript/ajax?
This can be achieved by adding the following META tags in the HEAD of your HTML. These tags will clear the cookies when the window is closed. hence the user need to relogin the next time.
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
1.1I have to close the session when the user abruptly close the browser.
There is no reliable way to track it, you could continuously poll to server using AJAX, and if you stop receiving the ajax call consider that browser has been closed
Or call a javascript method that signals your server about close, but this will not work on weird shutdown/crashes
1.2. When the user tries 'open in a new tab' - The user should be forwarded to the 'login page' in the new tab
If user is logged in, and you want to manage another session of browser's new tab, that is not possible, because browser manages cookies centrally (amongst all tabs and window). so when it sends the request it will add the cookie in the header so your application will not be able to identify,
If you manage session using other technique like jSessionId in url parameter it is possible to do but not a 100% sure way because user can play with sessionID
I have a JSF 2.1, Primeface 3.2, Spring/Spring security 3.05 web application. I signin with an account and do some UI manipulation (button click, some ajax actions, etc). I logout and then login with another user, I see the same view (means the same state after the manipulations done by the previous user)
I tried some tricks like change the scope to request, invalide session, set face redirect to true after logout, set javax.faces.STATE_SAVING_METHOD to client etc. but nothing works.
Edit 1: Tried using different browers with different users the same time I see the same view.
Edit 2:
Scenario 1: I have a with a list of checkbox, I tick some checkbox and then I click a who fire a event of a managedBean (actionListener="#{xxxxxMB.doSomething}") and I logout and login, the checkboxs keep ticked,
Scenario 2: the same I tick some checkbox and then I logout and login, the checkboxs are not ticked.
I have a JSF 1.2 login page (login.xhtml) that has 2 sub-forms - menuForm, loginForm.
Using a browser, I am able to navigate from the login page to a productList.xhtml page by clicking on the Login button within the loginForm.
....
For allowing the Google Crawler to crawl through my pages that require login, I am trying to test a form submit with a Java program on the loginForm to see if I can retrieve the productList.xhtml page.
The hidden fields (View Source from browser) in the login.xhtml page includes the following:
username
password
autoScroll
loginForm
loginButton
javax.faces.ViewState
I have submitted all the values from above (except the javax.faces.ViewState) in my Java program, but I keep getting only the login.xhtml page back in my response. Why is this?
I cannot submit the javax.faces.ViewState because there is no state on the server-side for the form when a submit happens from the Java program. How do I submit a form that does not yet have a view state?
For allowing the Google Crawler to crawl through my pages that require login
A login requires a session (basically: a cookie). But web crawlers does not maintain the session (basically: they do not maintain cookies). So it ends up here. You have to remove the login form and replace all navigation commandlinks by normal links in order to let any webcrawler index your pages.
It's by the way beyond me why you would like to make restricted pages crawlable (thus: publicitly available). Why is the login there in first instance?
I have submitted all the values from above (except the javax.faces.ViewState) in my Java program, but I keep getting only the login.xhtml page back in my response. Why is this?
Because you omitted the view state field. JSF won't process the form submit then. For a part, this is a safeguard against CSRF attacks and for other part, this is because JSF is a stateful component based MVC framework.
I cannot submit the javax.faces.ViewState because there is no state on the server-side for the form when a submit happens from the Java program. How do I submit a form that does not yet have a view state?
You need to either maintain the session (basically: send all cookies from the server back in subsequent requests), or to set the state saving method in web.xml to client and you also need to pass the view state hidden field along with the form submit request.