Why is required="true" not triggered when rendered="false"

I have a some doubts about parsing of html tags in facelet. Let we have facelet which contains the follow

<h:inputText id="username"
             title="My name is: "
             requiredMessage="Error: A name is required."
             maxlength="25" />
<h:commandButton id="submit" value="Submit" action="response">

After submit click i haven't Error: A name is required. Why? username just not rendered, and after submit click there is no value in username.


The rendered attribute is also evaluated during validations and update model values phases. For evidence, check javax.faces.component.UIInput source code (line numbers are as per Mojarra 2.2.0):

696     public void processValidators(FacesContext context) {
698         if (context == null) {
699             throw new NullPointerException();
700         }
702         // Skip processing if our rendered flag is false
703         if (!isRendered()) {
704             return;
705         }
735     public void processUpdates(FacesContext context) {
737         if (context == null) {
738             throw new NullPointerException();
739         }
741         // Skip processing if our rendered flag is false
742         if (!isRendered()) {
743             return;
744         }

The explanation is simple: this is a safeguard against tampered (spoofed/hacked) HTTP requests wherein endusers purposefully manipulate the HTTP request in an attempt to set values and/or invoke actions of hidden inputs/commands which they are most likely simply not allowed to update or invoke, such as a delete button which shows only when the user has admin role:

<h:commandButton value="Delete" ... rendered="#{request.isUserInRole('ADMIN')}" />

Note: component's readonly and disabled attributes are also treated this way. For your particular purpose, use CSS display: none instead.

<h:inputText ... style="display:none" />

(note: this is a kickoff example, using style attribute is bad practice in HTML/CSS perspective, prefer styleClass with a concrete CSS file)

Although I wonder the concrete functional requirement behind this, this is bad for UX. Perhaps you were just randomly experimenting around without first studying the JSF specification let alone JSF source code?

Need Your Help

Image map control (ocx)

vb6 imagemap ocx

do you know of any image map control, that can used to translate an image to clickable regions?

Is there a List<T> in .NET 2 that raises events when the list changes?

.net collections observablecollection

I have used ObservableCollection&lt;T&gt; in the past, but that seems to belong to WPF and therefore .NET 3.