myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bjørn T Johansen <...@havleik.no>
Subject Ajax call and session timeout?
Date Fri, 16 Jan 2015 14:59:13 GMT
This is not strictly just a myfaces question but perhaps someone can help me still... :)

I finally thought I woulf see if I could fix the problem of just no response when trying to
use ajax calls when the session has timed out and I am almost there...
I am using Primefaces 5.1, Spring 4.1.4 and Spring Security 3.2.5 deployed in Tomcat 8 and
I have solved this using the following..:


<beans:bean id="authenticationEntryPoint"
                class="no.havleik.weather.spring.JsfLoginUrlAuthenticationEntryPoint" p:loginFormUrl="/login.xhtml"
                p:redirectStrategy-ref="redirectStrategy" />

    <beans:bean id="redirectStrategy" class="no.havleik.weather.spring.JsfRedirectStrategy"
/>

    <http auto-config="true" use-expressions="true" entry-point-ref="authenticationEntryPoint">
     ........



returning the following xml when expired:

.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
                .append("<partial-response><redirect url=\"")
                .append(redirectUrl)
                .append("\"></redirect></partial-response>").toString();



And this works, as when I try to do an ajax call after session timeout, I am redirected to
the login.xhtml page.
But what is strange, is that after I login I show my index.xhtml page which works fine the
first time (just after I login after expired). But if move
away from this view and then go back to index.xhtml, I get a ViewExpiredException. I have
tried to solve this by adding my custom exceptionhandler
where I mainly do this when the ViewExpiredException occurs..:


facesContext.setViewRoot(facesContext.getApplication().getViewHandler().createView(facesContext,
viewExpiredException.getViewId() +
"?faces-redirect=true"));
facesContext.renderResponse();



The problem is that the view that is created shows an XML like this:

<partial-response id="j_id1"><changes><update id="mainform:growl"><span
id="mainform:growl"></span><script id="mainform:growl_s"
type="text/javascript">$(function(){PrimeFaces.cw('Growl','widget_mainform_growl',{id:'mainform:growl',sticky:false,life:6000,escape:true,msgs:[]});});</script></update><update
id="mainform:weatherTable"><tr data-ri="20" data-rk="11.12.2014" class="ui-widget-content
ui-datatable-even ui-datatable-selectable" role="row"
aria-selected="false"><td role="gridcell">11.12.2014</td><td role="gridcell">1,6

...........

</update><update id="j_id1:javax.faces.ViewState:0">-5276350923272627949:7555540505775029876</update><extension
ln="primefaces"
type="args">{"totalRecords":20280}</extension></changes></partial-response>



instead of the html page. Refreshing the page displays the page as it should..


So, 2 questions:

- How can I display the correct html view instead xml?
- And why am I getting ViewExpiredException the second time I display the view instead of
the first time after session timeout?



Regards,

BTJ

-- 
-----------------------------------------------------------------------------------------------
Bjørn T Johansen

btj@havleik.no
-----------------------------------------------------------------------------------------------
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"
-----------------------------------------------------------------------------------------------

Mime
View raw message