我最近将我的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>