users@javaserverfaces.java.net

Required input field not validated

From: Stanimir Stamenkov <stanio_at_yahoo.com>
Date: Fri, 22 Jul 2011 04:29:43 +0300

I'm using JSF 1.2 (with Facelets) and a form like:

<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html">
    ...
    <h:messages />
    <h:form id="test">
        <label>
            Field:
            #{''}
            <h:inputText id="field" value="myBean.field" required="true" />
        </label>
        #{''}
        <h:commandButton value="Submit" action="myBean.action" />
    </h:form>
    ...
</html>

I've noticed if I remove the text input element on the client side
(e.g. using the various browser DOM inspecting tools available) and
submit the form, then the "required" check for the
<h:inputText id="field"> component is not performed, therefore the
"myBean.action" executed, where it fails because it assumes the
"myBean.field" has been set appropriately. What is the rationale
behind this behavior? Could it be customized to always require a
"field" value submitted?

Further, if "myBean.field" had a previous non-empty value set,
submitting no "field" by the client leaves the old value in place,
no validation errors, and "myBean.action" executed referring to the
old value, in which case the outcome may not be desired.

-- 
Stanimir