Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
906 views
in Technique[技术] by (71.8m points)

jsf execution order of f:events

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...