在Glassfish v3中使用JNDI配置/查找为JavaServer Faces设置项目阶段

4

我正在尝试在GlassFish应用服务器v3中使用JNDI属性设置JavaServer Faces项目阶段。

我将阶段属性设置为开发阶段,但我的应用程序始终接收到生产阶段。

enter image description here

我在Windows系统上使用GlassFish Server Open Source Edition 3.1(构建43)。

为了在JSF页面中呈现项目阶段,我使用以下代码:

<h:outputText value="Stage:#{facesContext.application.projectStage}"/>

在应用程序中使用项目阶段还需要其他任何东西吗?该应用程序没有web.xml文件。

3个回答

3
一切都正确,但是使用value = Development而不是stage=Development, 即在属性名称字段中将stage替换为value

1

您需要将下列内容添加至您的web.xml文件。若使用'stage'则此方法可行。

<resource-ref>
        <res-ref-name>jsf/ProjectStage</res-ref-name>
        <res-type>java.lang.String</res-type>
        <mapped-name>javax.faces.PROJECT_STAGE</mapped-name>
</resource-ref>

这将GF的全局JNDI属性映射到JSF中的引用查找。

0

至少需要在web.xml中包含以下条目:

<resource-ref>
    <res-ref-name>jsf/ProjectStage</res-ref-name>
    <res-type>java.lang.String</res-type>
    <mapped-name>javax.faces.PROJECT_STAGE</mapped-name>
</resource-ref>

属性名称取决于您使用的工厂类:

  • 对于org.glassfish.resources.custom.factory.PrimitivesAndStringFactory,请使用value=Development
  • 对于com.sun.faces.application.ProjectStageJndiFactory,请使用stage=Development

您也可以使用asadmin设置资源:

C:\glassfish5\bin> asadmin.bat create-custom-resource --restype java.lang.String --factoryclass org.glassfish.resources.custom.factory.PrimitivesAndStringFactory --property "value=Development" javax.faces.PROJECT_STAGE

C:\glassfish5\bin> asadmin.bat create-custom-resource --restype java.lang.String --factoryclass com.sun.faces.application.ProjectStageJndiFactory --property "stage=Development" javax.faces.PROJECT_STAGE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接