Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsf execution order of f:events

Tags:

events

jsf

What is the execution order of those?

Here is a question about possible f:event event names: List of JSF 2 events?

preRenderComponent
preRenderView
postAddToView
preValidate
postValidate

I want to check if a User is saved in a session bean is logged in and if not redirect to the login site, which needs to occur before view-param conversion phase since the used converter depends on the logged in User. 'preValidate' seems to take place after conversion and so I need an earlier event.

<f:event type="preRenderView" listener="#{beanA.checkLoggedIn()}"/>
<f:viewParam name="param" value="#{beanB.param}" converter="#{beanB.converter}" required="true"/>

I could have put 'checkLoggedIn()' in 'beanB' too, but tried to use a separate request scoped bean just for the check so that I could reuse it easily.

like image 414
djmj Avatar asked Dec 22 '12 00:12

djmj


1 Answers

What is the execution order of those?

  • postAddToView runs right after the component is added to view during view build time (which is usually during restore view phase, but can also be during render response phase, e.g. navigation).
  • preValidate runs right before the component is to be validated (which is usually during validations phase, but can also be apply request values phase if immediate="true").
  • postValidate runs right after the component is been validated (which is usually during validations phase, but can also be apply request values phase if immediate="true").
  • preRenderView runs right before the view is rendered during render response phase.
  • preRenderComponent runs right before the component is rendered during render response phase.

Click the links to see detailed description in javadoc introduction.


I want to check if a User is saved in a session bean is logged in and if not redirect to the login site, which needs to occur before view-param conversion phase since the used converter depends on the logged in User. 'preValidate' seems to take place after conversion and so I need an earlier event.

You should use a simple servlet filter for this, not a JSF event. I've posted several examples before:

  • Is there any easy way to preprocess and redirect GET requests?
  • Are there some issue at inserting some check into template?
like image 74
BalusC Avatar answered Nov 09 '22 21:11

BalusC