This content has been marked as final.
Show 6 replies
-
1. Re: An PhaseListener blocks richfaces css styles
ilya_shaikovsky Jun 9, 2009 8:30 AM (in response to faraon02)Non-redirect navigation not intended to works with ajax requests. Is it your case?
-
2. Re: An PhaseListener blocks richfaces css styles
faraon02 Jun 10, 2009 4:11 AM (in response to faraon02)Hi Ilya,
thanks for the answer
Short case description:
PhaseListener checks if a user accessing a page which requires the user personal data, and if its true, then the PhaseListener redirects request to certain predefined page.
The solution works fine except that richfaces CSS styles are not applied to the components.
I defined the rule for "login" outcome as:<navigation-case> <from-outcome>login</from-outcome> <to-view-id>/common/login.jsp</to-view-id> <redirect/> </navigation-case>
So JSF controller must make redirect to a specified resource.
Anyway, if even I would make this redirect manually byFacesContext.getCurrentInstance().getExternalContext().redirect("http://localhost:8080/hms/common/login.jsf");
I wouldnot see the applied CSS styles.
The strangest thing is that CSS styles is not applied even if user is logged in and redirect is not performed - I mean that code snippetif (!isCommonPage && getCurrentSystemUser(fc) == null) { debug("User is not logged - redirecting to login page"); NavigationHandler nh = fc.getApplication().getNavigationHandler(); //TODO add message in faces context!!!! nh.handleNavigation(fc, null, "login"); }
is not executed.
How can I fix this? Apply another ways of session check? Redefine the default richfaces CSS styles? I'm wondered that noone has seen the same problem before... -
3. Re: An PhaseListener blocks richfaces css styles
nbelaevski Jun 10, 2009 4:46 AM (in response to faraon02)The PhaseListener doesnt intercept the requests for stylesheets above, so I dont know how its possible that call to navigationHandler affects CSS fetching.
In fact, it does; isCommonPage = false for CSS resources. Use this: org.ajax4jsf.webapp.WebXml#getFacesResourceKey(HttpServletRequest) to determine whether the request is resource request or not. -
4. Re: An PhaseListener blocks richfaces css styles
faraon02 Jun 10, 2009 6:36 AM (in response to faraon02)"nbelaevski" wrote:
The PhaseListener doesnt intercept the requests for stylesheets above, so I dont know how its possible that call to navigationHandler affects CSS fetching.
In fact, it does; isCommonPage = false for CSS resources. Use this: org.ajax4jsf.webapp.WebXml#getFacesResourceKey(HttpServletRequest) to determine whether the request is resource request or not.
Hi Nick,
I had performed the debug before - PhaseListener doesnt intercept the PhaseEvent for viewId "/a4j/s/....something" - thats why I was wondered how PhaseListener impacts the CSS fetching.
Anyway - could you give me an example with org.ajax4jsf.webapp.WebXml#getFacesResourceKey usage?
Zaranee spasibo :) -
5. Re: An PhaseListener blocks richfaces css styles
nbelaevski Jun 10, 2009 7:40 AM (in response to faraon02)If getFacesResourceKey() returns not null, then it's resource request. Use WebXml.getInstance() to obtain instance of WebXml class.
-
6. Re: An PhaseListener blocks richfaces css styles
faraon02 Jun 11, 2009 5:36 AM (in response to faraon02)"nbelaevski" wrote:
If getFacesResourceKey() returns not null, then it's resource request. Use WebXml.getInstance() to obtain instance of WebXml class.
Hi Nick,
thanks - it works!
the final version would look like:public void afterPhase(PhaseEvent event) { debug("afterPhase started " + event.getPhaseId() + " source " + event.getSource()); FacesContext fc = event.getFacesContext(); String view = fc.getViewRoot().getViewId(); debug("afterPhase viewId=" + view); //is page is should be checked? boolean isCommonPage = view.indexOf("/common") != -1; if (WebXml.getInstance(fc).getFacesResourceKey((HttpServletRequest) fc.getExternalContext().getRequest()) != null) { return; } if (!isCommonPage && getCurrentSystemUser(fc) == null) { debug("User is not logged - redirecting to login page"); NavigationHandler nh = fc.getApplication().getNavigationHandler(); //TODO add message in faces context!!!! nh.handleNavigation(fc, null, "login"); } else { debug("User is logged in - go to page " + view); } debug("afterPhase finished " + event.getPhaseId() + " source " + event.getSource()); }