Is there a way (in JSF 2) to catch a Conversation timeout and redirect a user to a new page? I'm getting nasty NullPointerExceptions when the conversation times out.
I could redirect the user on all NPE's, but that seems like too big a net.
This is a bug with Weld 1.0.0 the RI for CDI
https://jira.jboss.org/browse/WELD-550
This has apparently been fixed in the Weld trunk, I don't know in which release it's available. In trunk, a org.jboss.weld.context.NonexistentConversationException exception is thrown, when trying to access an expired conversation. This Exception can be trapped with a custom ExceptionHandler, and redirect the user to an appropriate page. See this blog for more details on creating an custom ExceptionHandler:
http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2
I'm also currently working with CDI-conversations and trying to build a Conversation-based app. I solved most of the problems (not easy without any useful tutorial out there...). Maybe i can help.
My first problem was that i didn't redirect the view&add the cid to GET when navigating to the next page of the Conversation-UseCase. I asked a related question in the Weld Forum.
There i learned that in my managed/weld-bean i have to redirect to the next page and add the cid as a GET-parameter.
Only then you can access conversation-scoped elements of your bean on the next page.
So when i enter the first page of my conversation i'm calling a start-method (e.g. by a commandLink) in my ConversationScoped-Bean, like this:
public String startRegister() {
if (conversation.isTransient)
conversation.begin();
return "register_start?faces-redirect=true&includeViewParams=true&cid=" + conversation.getId()
}
Does that solve your problem?
I also asked a question at StackOverflow related to the ViewExpiredException that has to be handled when working with conversations - here.
Related
on EE 2.x the Freemember addon allowed to directly redirect the user after login/logout to a specified page (avoiding the default login/logout confirmation page).
Since the Freemember addon is EOL, how can I achieve the same thing on EE 5.x ?
First you could use Custom System Messages
You can also do this with ajax (dont't have an example at hand)
You could use the member_member_login_single hook in a simple extension and redirect it with php.
function member_member_login_single($hook_data)
{
if(isset($_POST['RET'])){
header('location: '.$_POST['RET']);
exit;
}
}
I ended up using the member_member_login_single($hook_data) in a custom extension to get this done. Works.
In the past, I've seen other extensions be able to redirect you to an info page after the update is completed. I will soon be releasing an update and would like to inform users as soon as the update is completed. Not after they click the icon.
I came across update_info_url which can be placed in the manifest.json however it is unclear if it has been depreciated or not
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Updates#Update_objects
All other google results date back to 2009.
I'm just trying to figure out how to go about this, i believe I definitely have seen other extensions achieve this.
You can use something like this in the background script:
chrome.runtime.onInstalled.addListener(details => {
if (details.reason == 'update'){
chrome.tabs.create({url:'https://example.com/extensionupdated.html'});
}
});
I am new to servlet filter.
I am using JSF 2.2, Wildfly 8.1. I have figured out that if user clicks log out link when session is already expired then when user logs in again the system will continiously fire exception of session expired. BalusC wrote to write servlet filter which will delete all cookies of specific domain before user will see welcome page.
How to write servlet filter which will destroy all cookies related to specific domain (domain.com) when new session will start? I played with it and absolutely confused. sorry for my a little experience in jsf.
I think you need to set cookie.setMaxAge(0);for all the cookie for that domain.
Inside your filter(which should be used for Logout request only) or in Logout servlet(if any) you can write below line to delete all cookie.
Cookie[] cookies = req.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
cookie.setValue("");
cookie.setPath("/");
cookie.setMaxAge(0);
resp.addCookie(cookie)
}
}
I have been trying to find a solution to my problem for 2 days now and I am really stuck. Here's the problem:
I have an MVC application (with Dependency injection and the works) with just one webform. This page needs to be a webform because it has a ReportViewer in it and please correct me if I am wrong but an MVC View is incompatible with server controls like ReportViewer. This is the navigation flow of the pages:
Home page navigates to the ReportList page
ReportList page displays the reports that a user is able to view and navigates to the Report page and passes it the ID of the report that the user selected.
Report page should look up the ReportPath and the ServerUrl from the database based on the ID passed from the ReportList page at the same time authorizing the user, whose permissions are stored in the database.
I could potentially pass the ReportPath and the ServerUrl as part of the query string so that the report page (aspx, not driven by a controller) does not have to go to the database to get these values. The problem however is how to check that the user is authorized to view the report (someone could just use a link to look at the report).
I did try to hook it into the MVC model and inherited the page from the ViewPage class. The problem there is that the page kept reloading itself for some reason. I still want my page to do as little as possible and a controller to handle calls to the authorization attribute and to the business layer. So, as a last resort, I want to call the controller from the aspx page but I can't create an object of it becasue dependency injection.
Can someone please provide some guidance on this? I have all the code available but don't know what to post.
I found out the answer and posting here if it helps anyone.
I added another class called ReportManager, which the aspx code behind calls to execute the requests. The ReportManager simulates the Controller call through this code:
var routeData = new RouteData();
routeData.Values["controller"] = "Report";
routeData.Values["action"] = "SomeAction";
routeData.Values["SomeRouteValueKey"] = "someroutevalue";
var requestContext = new RequestContext(new HttpContextWrapper(HttpContext.Current), routeData);
IController controller = DependencyResolver.Current.GetService<ReportController>();
controller.Execute(requestContext);
I am creating a custom portlet.
And I need to log-out the User from the portal after he performs some operation in my custom portlet. I am extending liferay's MVCPortlet.
In one of MyPortlet's action methods I need to write the code to logout the user and then redirect it to the home page.
Update:
I tried the following which I think logs out the user but does not redirect to the home page after logging out:
actionResponse.sendRedirect(PortalUtil.getPortalURL(actionRequest) + "/c/portal/logout");
Thanks All
Well this may be a very late reply, but it may help somebody
Firstly, you have to validate the session and the re-direct to the logout URL. Otherwise, the session remains and the user is moved to the landing page, even though we redirect to the logout url. So, this is what one should do
HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
request.getSession().invalidate();
actionResponse.sendRedirect(themeDisplay.getURLSignOut());
Hope this helps.
I also did not find a way to send a specific redirect by using liferay's default logout (/c/portal/logout). So I logged out the user programmatically with the util class AuthenticatedSessionManagerUtil and
afterwards sending a specific redirect location within the response object, e.g. response.sendRedirect(yourLocation)
Note:
With Liferay 7.2 I used AuthenticatedSessionManagerUtil.signOutSimultaneousLogins(userId) instead of AuthenticatedSessionManagerUtil.logout(userId) which did not work for me.
hth
You can redirect to c/portal/logout
more precisely :
actionResponse.sendRedirect("/c/portal/logout/");
Just leaving this here after facing this problem (LR7):
try {
AuthenticatedSessionManagerUtil.logout(request, response);
request.setAttribute(WebKeys.LOGOUT, true);
}
All you have to do is
perform operation: at the end of operation use this:
HttpSession session = PortalUtil.getHttpServletRequest(request).getSession();
session.invalidate();
try {
System.out.println(" redirecting to the required page");
response.sendRedirect(themeDisplay.getPortalURL() + "/page-on-which-to-be-redirected");
} catch (IOException e1) {
e1.printStackTrace();
}