简体   繁体   English

javax.faces.PROJECT_STAGE 的使用

[英]Uses of javax.faces.PROJECT_STAGE

I wanted to understand impact of 'javax.faces.PROJECT_STAGE' property for a JSF application.我想了解“javax.faces.PROJECT_STAGE”属性对 JSF 应用程序的影响。 A nice use case was presented in below links下面的链接中提供了一个很好的用例

https://dzone.com/articles/jsf-20-new-feature-preview-ser https://dzone.com/articles/jsf-20-new-feature-preview-ser
http://www.java-tutorial.ch/java-server-faces/jsf-project-stage http://www.java-tutorial.ch/java-server-faces/jsf-project-stage

Except presenting validation error messages, is there any other use case where this property really helps?除了显示验证错误消息外,是否还有其他用例可以证明此属性确实有帮助? I understand that we can check this variable to identify the environment and change certain functionality, however is there anything else that JSF does automatically to help developers?我知道我们可以检查这个变量来识别环境并更改某些功能,但是 JSF 是否会自动做任何其他事情来帮助开发人员? Would be great if you can share the experiences from your project?如果你能分享你的项目经验会很棒吗?

Setting this param to Development enables better error messages, including in the client-side JavaScript, at the cost of some performance.将此参数设置为Development可以提供更好的错误消息,包括在客户端 JavaScript 中,但会牺牲一些性能。

While setting this param to Production will turn off some error messages, and emphasize performance .将此参数设置为Production将关闭一些错误消息,并 强调 performance

Source:来源:
JSF 2.0 Reminder: Project Stage JSF 2.0 提醒:项目阶段

根据wutzebaer对此链接帖子commentjavax.faces.PROJECT_STAGE属性可以控制是否启用某些功能(例如资源缓存)。

When we setting the PROJECT_STAGE as production we will get better error message, for example when we missed h:form tag around input fields then we may get following error message when stage is set as Development and when the stage is set as Production (or any value other than Development) we won't get any error message.当我们将 PROJECT_STAGE 设置为生产时,我们将获得更好的错误消息,例如,当我们错过了输入字段周围的 h:form 标记时,当阶段设置为开发时以及将阶段设置为生产(或任何Development 以外的值)我们不会收到任何错误消息。

The form component needs to have a UIForm in its ancestry.表单组件需要在其祖先中有一个 UIForm。 Suggestion: enclose the necessary components within <h:form>建议:将必要的组件包含在<h:form>

Cache Busting for Resources during development开发过程中的资源缓存破坏

By resources, I refer to static resources such as stylesheets, javascript libraries, logo's and pictograms, etc.对于资源,我指的是静态资源,例如样式表、javascript 库、徽标和象形图等。

By default, resources are loaded without any cache expiration (expires at max age or something).默认情况下,资源加载时没有任何缓存过期(在最大年龄或其他时间过期)。 This is so, because resources are assumed to be static, in that they do not change during the lifespan of the Servlet Container.之所以如此,是因为假定资源是静态的,因为它们在 Servlet 容器的生命周期内不会更改。 We benefit that way from caching those resources on the Client Side (Web Browser caching).我们从在客户端缓存这些资源(Web 浏览器缓存)中受益。

However, when releasing a new version of a library that might wrap a group of resources, we do not want users to get stuck with the old version of a resource.但是,在发布可能包含一组资源的新版本库时,我们不希望用户卡在旧版本的资源上。 Typically Implementations, and as per the spec, resources will get automatically suffixed with the library name and version as query attributes.通常实现,并且根据规范,资源将自动以库名称和版本作为查询属性后缀。 A typical resource will automatically be output as something like:典型的资源将自动输出为:

<link type="text/css" rel="stylesheet" href="/nqp-web/javax.faces.resource/components.css.xhtml?ln=primefaces&amp;v=6.2">

This is handled by using a specific implementation of Resource .这是通过使用Resource的特定实现来处理的。

So as you release new versions of a library, your users wont get stuck with old versions of resources in their cache.因此,当您发布库的新版本时,您的用户不会被缓存中的旧版本资源所困。

However during development work, the version does not increase, but you still want the cache to expire, preferably immediately.然而在开发工作期间,版本并没有增加,但您仍然希望缓存过期,最好立即过期。

The default implementation is usually to make sure that based on the value of javax.faces.PROJECT_STAGE , specifically being DEVELOPMENT , the expire is set to immediate.默认实现通常是为了确保基于javax.faces.PROJECT_STAGE的值,特别是DEVELOPMENT ,将过期设置为立即。 You can see that in Mojarra's ResourceImpl for example:例如,您可以在 Mojarra 的ResourceImpl看到:

long expiresTime;
if (FacesContext.getCurrentInstance().isProjectStage(Development)) {
  expiresTime = new Date().getTime();
} else {
  expiresTime = new Date().getTime() + maxAge;
}

Logging日志记录

As @vrcca already mentioned, a quick search for usages of isProjectStage reveals that this mostly just turns on additional logging when set to DEVELOPMENT .正如@vrcca 已经提到的, 快速搜索isProjectStage用法表明,当设置为DEVELOPMENT时,这主要只是打开额外的日志记录。


References参考文献

将 PROJECT_STAGE 设置为 Development 的另一个功能是,我们还可以在不重新启动服务器的情况下查看 .xhtml 文件中的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当javax.faces.PROJECT_STAGE为Production时,未定义mojarra - mojarra is not defined when javax.faces.PROJECT_STAGE is Production 如何从视图/内部代码访问javax.faces.PROJECT_STAGE? - How to access javax.faces.PROJECT_STAGE from the view/inside code? 未被捕获的ReferenceError:当javax.faces.PROJECT_STAGE为Production时未定义mojarra - Uncaught ReferenceError: mojarra is not defined when javax.faces.PROJECT_STAGE is Production Javax Faces的搜索解决方案 - Search Solution for javax faces 在 Glassfish v3 中使用 JNDI 配置/查找为 JavaServer Faces 设置项目阶段 - Set project stage for JavaServer Faces with JNDI configuration/lookup in Glassfish v3 java.lang.NoClassDefFoundError:javax / faces / FacesWrapper错误,尽管所需的类已添加到RichFaces中的项目类路径中 - java.lang.NoClassDefFoundError: javax/faces/FacesWrapper error though the required classes been added to the project classpath in RichFaces javax.faces.view.facelets.TagAttributeException - javax.faces.view.facelets.TagAttributeException javax.faces.DEFAULT_SUFFIX无效 - javax.faces.DEFAULT_SUFFIX not working 如何在JSF中减少javax.faces.ViewState - How to reduce javax.faces.ViewState in JSF 似乎已忽略javax.faces.application.ViewExpiredException - javax.faces.application.ViewExpiredException seemingly ignored
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM