JSF PROJECT_STAGE生产和f:param

时间:2019-02-05 19:17:35

标签: java jsf

我最近将我的JSF版本从2.2更改为2.3,从而将javax.faces.PROJECT_STAGE的默认值从Development修改为Production。这导致了意外的行为-f:param的值不再包含在ExternalContext requestParameterMap中。

用例很简单-我希望仅在发生特定的用户操作时才执行验证。例如:

<h:commandLink value="Save changes">
    <f:param name="performValidation" value="true"/>
    <f:ajax listener="#{bean.save()}"
            execute="#{cc.clientId}:content"
            render="#{cc.clientId}:content" 
            onevent="showLoader"/>
</h:commandLink>

这会执行一些输入,包括带有验证器的隐藏输入:

<h:inputText style="display:none;" value="abc" validator="#{bean.validate}"/>

验证器代码如下:

public void validate(FacesContext context, UIComponent component, Object value) {
    if (!"true".equals(context.getExternalContext().getRequestParameterMap().get("performValidation"))) {
        return;
    }

    ... Prepare the List<FacesMessage> and throw it in ValidatorException if not empty ...
}

消息显示在单个h:messages组件中,该组件放置在带有rendered="#{facesContext.validationFailed}"的渲染容器中。

javax.faces.PROJECT_STAGE中的web.xml设置为Development可解决此问题。不过,我很想了解-为什么Production设置会破坏此代码?


编辑:

我正在使用Mojarra: 2.3.5.SP2。在下面可以看到POM。

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.asdf</groupId>
    <artifactId>asdf</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-7.0</artifactId>
            <version>1.1.0.Final</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>

        <!-- Omnifaces -->
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>2.4</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>5.2.10.Final</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.0.10.Final</version>
            <scope>provided</scope>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerVersion>1.8</compilerVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

0 个答案:

没有答案