This discussion is archived
6 Replies Latest reply: Nov 2, 2012 3:56 AM by gimbal2 RSS

Bug with validation or rendering after validation failure (?)

jmsjr Newbie
Currently Being Moderated
Can anyone confirm the behaviour on other J2EE containers that I will describe below ?

h2. Environment:

JBoss 7.1.1 (Brontes)
JDK 1.7.0_06 32-bit
Win7 64-bit
17:40:44,365 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-13) Initializing Mojarra 2.1.7-jbossorg-1 (20120227-1401)
Below is the very simple test case:


h2. 1) A very simple request-scoped bean:
package test;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.validation.constraints.NotNull;

@ManagedBean
@RequestScoped
public class RequestBean implements Serializable {
     
     private static final long serialVersionUID = 1L;

     @NotNull(message="Input 1 is required")
     private String input1;
     
     @NotNull(message="Input 2 is required")
     private String input2;
     
     public String getInput1() {
          return input1;
     }
     
     public String getInput2() {
          return input2;
     }
     
     public void setInput1(String input1) {
          this.input1 = input1;
     }
     
     public void setInput2(String input2) {
          this.input2 = input2;
     }

}
h2. 2) A very simple test.xhtml page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"> 

<h:head></h:head> 
<body>

<h:form>

       <h:panelGrid columns="2">
           Input 1: <h:inputText value="#{requestBean.input1}" />
           Input 2: <h:inputText value="#{requestBean.input2}" />
           <h:commandButton id="submit" value="Submit"/><br/>
           <h:messages/><br/>
       </h:panelGrid>
</h:form> 

</body> 
</html>
h2. 3. web.xml contents:
<?xml version="1.0"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 <display-name>test</display-name>
  <context-param>
  <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
  <param-value>true</param-value>
 </context-param>
  <context-param>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>client</param-value>
 </context-param>
 <!--
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
-->
 <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.faces</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>
</web-app>
h2. 4. faces-config.xml contents:
<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
     version="2.1">

</faces-config>
h2. 5. Contents of WEB-INF/lib:
salvojo@AAS-AUD20901BL /cygdrive/c/jboss-as-7.1.1.Final/standalone
$ ls -alt deployments/test.war/WEB-INF/lib/
total 1384
drwx------+ 1 Administrators Domain Users      0 Nov  2 17:40 ..
drwx------+ 1 Administrators Domain Users      0 Nov  2 16:56 .
-rwx------+ 1 Administrators Domain Users 393259 Nov  2 16:56 standard.jar
-rwx------+ 1 Administrators Domain Users  21029 Nov  2 16:56 jstl.jar
-rwx------+ 1 Administrators Domain Users  38015 Nov  2 16:56 commons-logging.jar
-rwx------+ 1 Administrators Domain Users 139966 Nov  2 16:56 commons-digester.jar
-rwx------+ 1 Administrators Domain Users 559366 Nov  2 16:56 commons-collections.jar
-rwx------+ 1 Administrators Domain Users 188671 Nov  2 16:56 commons-beanutils.jar
-rwx------+ 1 Administrators Domain Users  48742 Nov  2 16:56 common-annotations.jar
h2. 6. The test case

h4. 6.1 Open the test.jsf page with your browser

h4. 6.2 Click on Submit WITHOUT specifying any values for both Input1 and Input2.

Expected behaviour: Messages displayed that both input fields are required.
Actual: As expected

h4. 6.3 Supply values for both Input1 and Input2, then click Submit

Expected behaviour: No validation messages displayed. Entered values remain in the input field
Actual: As expected

h4. 6.4 Remove input value for Input1, then click Submit

Expected behaviour:
Validation message that Input1 is required.
Current value for Input1 remain blank.
Previous value for Input2 remain in the input field.

Actual: As expected

h4. 6.5 Remove input value for Input2, then click Submit ( both Input fields are now blank )

Expected behaviour:
Validation message both input fields are required.
Input value for Input1 remain blank.
Input value for Input2 remain blank.

h3. Actual ( NOT AS EXPECTED, see below )

Validation message both input fields are required.
Input value for Input1 remain blank.
Input value for Input2 remain NON-blank. The previous value before it was blanked out and submitted is rendered / displayed on the page*

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points