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
463 views
in Technique[技术] by (71.8m points)

java - Why not JSF pages are precompiled (atleast partially) but instead parsed, evaluated each time view is built?

I don't know whether it is true or not but from what I've read, I believe, JSF EL & xhtml pages are not pre-compiled & just used when needed but instead they are parsed, evaluated, compiled each time the view is built.

I fail to understand why this is done so! Why not just parse & compile it just once, ok atleast partially , rendering of some components may depend on a dynamically fetched variable so they may be rendered later but why delay that for all the components on page? Whatever maximum could be pre-compiled & made ready to use, why not do it just when the application is deployed? Wont this improve rendering time of the pages ?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Facelets is actually capable of "precompiling". You can control the Facelets refresh period with the context parameter javax.faces.FACELETS_REFRESH_PERIOD. You can set it to -1 in order to tell JSF to never re-compile/re-parse the Facelets files and actually hold the entire SAX-compiled/parsed XML tree (based on the XHTML compositions) in cache:

<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>-1</param-value>
</context-param>

Don't use this setting during development though, or you must restart the whole server on every edit of a Facelets file. Mojarra has a default setting of 2 (meaning, cache will be refreshed every 2 seconds). MyFaces has a default setting of -1 when javax.faces.PROJECT_STAGE is not set to Development.

You can if necessary control the Facelets cache by providing a custom FaceletsCacheFactory and FaceletsCache. Note that this is only available since JSF 2.1 and thus you'd need to redeclare your faces-config.xml conform JSF 2.1 in order to get <facelet-cache-factory> configuration setting to work.

To get a step further, the views which are built based on the XML tree (so, the entire UIViewRoot) could theoretically also be pooled. MyFaces is currently already making some effort in order to achieve this, see also issue 3664. My fellow Arjan Tijms is in his spare time also looking at it for Mojarra.


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

...