Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Add Option to expand meaning of required="true" for UIInput #1433

Closed
glassfishrobot opened this issue Nov 29, 2016 · 8 comments
Closed

Add Option to expand meaning of required="true" for UIInput #1433

glassfishrobot opened this issue Nov 29, 2016 · 8 comments

Comments

@glassfishrobot
Copy link

When you say required="true" on a UIInput component, the validation
must always take place, even when there is no entry in the request
corresponding to that component.

Background:

Consider this login page:

<h:inputText id=“userName” required=“true” 
             value=“#{backingBean.userName}” />

<h:inputSecret id=“password” required=“true” 
               validator=“#{backingBean.validatePassword}” 
               value=“#{backingBean.password}” />

<h:commandButton action=“/views/authenticatedUser.xhtml” />

If the postback is hacked such that the userName is present as a request
parameter, but the password is not, the password validator would be
bypassed. If the password validator is used as the entry point to
perform authentication, this could cause problems.

Now, it must be said that using a validator on a password field as the
entry point to perform authentication is a particular design choice.
This design choice runs a bit counter to the stated purpose of the
validation system, which is to ensure syntactic and some level of
semantic validity of fields. There are other ways to perform
authentication that do not rely on the validation system for this
purpose.

Nonetheless, we would like to accomodate this use case.

Proposal:

For JSF 2.3, I propose the following.

Modify PDF section 3.5.4 to read:

Spec> The render-independent property required is a shorthand for the
Spec> function of a required validator. If the value of this property is
Spec> true, there is an entry in the request payload corresponding to
Spec> this component
, and the component has no value, the component is
Spec> marked invalid and a message is added to the FacesContext
Spec> instance.

Modify the JavaDoc for UIInput.validate(). Modify the first bullet
point to read:

Spec> Retrieve the submitted value with getSubmittedValue(). If this
Spec> returns null, and the
Spec> javax.faces.component.UIInput.ALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUE
Spec> context-parameter is set to true (ignoring case), examine the
Spec> value of the "required" property. If the value of "required" is
Spec> true, continue as below. If the value of "required" is false, the
Spec> "required" attribute is not set, exit without further
Spec> processing. If the context-paramater is not set, or is set to
Spec> false (ignoring case) exit without further processing. (This
Spec> indicates that no value was submitted for this component.)

With these changes, the javadoc for UIInput.validateValue() can remain
unchanged.

Affected Versions

[2.3]

@glassfishrobot
Copy link
Author

Reported by @edburns

@glassfishrobot
Copy link
Author

@edburns said:
Work progressing on feature branch with of this JIRA.

@glassfishrobot
Copy link
Author

@edburns said:
Commit 07bc46d on feature branch has the fix.

@glassfishrobot
Copy link
Author

@edburns said:
The spec and impl changes have been pushed to master. I'll close this when the tree remains clear.

@glassfishrobot
Copy link
Author

@edburns said:
Tests seem to be clean, so closing this.

Passed

com.sun.faces.test.javaee8.uiinput.Spec1433IT.testSpec1433

@glassfishrobot
Copy link
Author

Marked as fixed on Wednesday, December 21st 2016, 10:11:42 am

@glassfishrobot
Copy link
Author

This issue was imported from java.net JIRA JAVASERVERFACES_SPEC_PUBLIC-1433

vsingleton added a commit to vsingleton/mojarra that referenced this issue Sep 23, 2017
…meaning of required="true" for UIInput javaee#1433

   javaee/javaserverfaces-spec#1433

   modified:   jsf-api/src/main/java/javax/faces/component/UIInput.java
   modified:   jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
   modified:   jsf-ri/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
   modified:   test/javaee6/pom.xml
   new file:   test/javaee6/uiinput-required-true/pom.xml
   new file:   test/javaee6/uiinput-required-true/src/main/java/com/sun/faces/test/javaee6/uiinput/Spec1433Bean.java
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/beans.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/faces-config.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/glassfish-web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/spec1433.xhtml
   new file:   test/javaee6/uiinput-required-true/src/test/java/com/sun/faces/test/javaee6/uiinput/Spec1433IT.java
vsingleton added a commit to vsingleton/mojarra that referenced this issue Sep 25, 2017
…meaning of required="true" for UIInput javaee#1433

   javaee/javaserverfaces-spec#1433

   modified:   jsf-api/src/main/java/javax/faces/component/UIInput.java
   modified:   jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
   modified:   jsf-ri/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
   modified:   test/javaee6/pom.xml
   new file:   test/javaee6/uiinput-required-true/pom.xml
   new file:   test/javaee6/uiinput-required-true/src/main/java/com/sun/faces/test/javaee6/uiinput/Spec1433Bean.java
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/beans.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/faces-config.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/glassfish-web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/spec1433.xhtml
   new file:   test/javaee6/uiinput-required-true/src/test/java/com/sun/faces/test/javaee6/uiinput/Spec1433IT.java
vsingleton added a commit to vsingleton/mojarra that referenced this issue Oct 11, 2017
…meaning of required="true" for UIInput javaee#1433

       javaee/javaserverfaces-spec#1433

	modified:   jsf-api/src/javax/faces/component/UIInput.java
	modified:   jsf-ri/src/com/sun/faces/config/WebConfiguration.java
	modified:   jsf-ri/src/com/sun/faces/context/FacesContextFactoryImpl.java
vsingleton added a commit to vsingleton/mojarra that referenced this issue Oct 11, 2017
…meaning of required="true" for UIInput javaee#1433

   javaee/javaserverfaces-spec#1433

   modified:   jsf-api/src/main/java/javax/faces/component/UIInput.java
   modified:   jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
   modified:   jsf-ri/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
   modified:   test/javaee6/pom.xml
   new file:   test/javaee6/uiinput-required-true/pom.xml
   new file:   test/javaee6/uiinput-required-true/src/main/java/com/sun/faces/test/javaee6/uiinput/Spec1433Bean.java
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/beans.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/faces-config.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/glassfish-web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/spec1433.xhtml
   new file:   test/javaee6/uiinput-required-true/src/test/java/com/sun/faces/test/javaee6/uiinput/Spec1433IT.java
vsingleton added a commit to vsingleton/mojarra that referenced this issue Oct 12, 2017
…meaning of required="true" for UIInput javaee#1433

   javaee/javaserverfaces-spec#1433

   modified:   jsf-api/src/main/java/javax/faces/component/UIInput.java
   modified:   jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
   modified:   jsf-ri/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
   modified:   test/javaee6/pom.xml
   new file:   test/javaee6/uiinput-required-true/pom.xml
   new file:   test/javaee6/uiinput-required-true/src/main/java/com/sun/faces/test/javaee6/uiinput/Spec1433Bean.java
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/beans.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/faces-config.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/glassfish-web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/spec1433.xhtml
   new file:   test/javaee6/uiinput-required-true/src/test/java/com/sun/faces/test/javaee6/uiinput/Spec1433IT.java
vsingleton added a commit to vsingleton/mojarra that referenced this issue Oct 12, 2017
…meaning of required="true" for UIInput javaee#1433

       javaee/javaserverfaces-spec#1433

	modified:   jsf-api/src/javax/faces/component/UIInput.java
	modified:   jsf-ri/src/com/sun/faces/config/WebConfiguration.java
	modified:   jsf-ri/src/com/sun/faces/context/FacesContextFactoryImpl.java
vsingleton added a commit to vsingleton/mojarra that referenced this issue Oct 12, 2017
…meaning of required="true" for UIInput javaee#1433

   javaee/javaserverfaces-spec#1433

   modified:   jsf-api/src/main/java/javax/faces/component/UIInput.java
   modified:   jsf-ri/src/main/java/com/sun/faces/config/WebConfiguration.java
   modified:   jsf-ri/src/main/java/com/sun/faces/context/FacesContextFactoryImpl.java
   modified:   test/javaee6/pom.xml
   new file:   test/javaee6/uiinput-required-true/pom.xml
   new file:   test/javaee6/uiinput-required-true/src/main/java/com/sun/faces/test/javaee6/uiinput/Spec1433Bean.java
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/beans.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/faces-config.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/glassfish-web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/WEB-INF/web.xml
   new file:   test/javaee6/uiinput-required-true/src/main/webapp/spec1433.xhtml
   new file:   test/javaee6/uiinput-required-true/src/test/java/com/sun/faces/test/javaee6/uiinput/Spec1433IT.java
@stiemannkj1
Copy link

stiemannkj1 commented May 11, 2018

This issue has been fixed in Mojarra by @vsingleton in the following versions:

  • 2.3.0
  • 2.2.16
  • 2.1.29-10
  • 1.2_15-06

You can take advantage of the fix by setting the following context-param in your web.xml:

<context-param>
    <param-name>javax.faces.ALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUE</param-name>
    <param-value>true</param-value>
</context-param>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants