0

I need to skip an input component inside a h:form from being processed/submitted as it is kept there only for pure presentational needs & does not submit value to any bean field. How do I disable its submittion along with other form inputs while the form is submitted?

      <h:form>
            <!--other input components-->

            <p:selectOneListbox id="deptsSel">
                <f:selectItems value="#{listRetriever.list}"
                               var="dept" itemLabel="#{namesDirectory.getName(dept)}" itemValue="#{dept}" />
            </p:selectOneListbox>

            <!--other input components-->
      </h:form>

I omitted the value attribute for p:selectOneListbox but while submitting the form it still gives validation error: "deptsSel: Validation Error: Value is not valid"

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294

1 Answers1

1

Disable it during postback as long as it's not rendering the response.

<p:selectOneListbox ... disabled="#{facesContext.postback and facesContext.currentPhaseId.ordinal ne 6}">

As part of JSF safeguard against hacked requests, the UIInput component's disabled attribute is namely also obeyed during request processing through all phases in the JSF lifecycle, including validations phase.


Unrelated to the concrete problem, might you be interested in knowing when and why exactly that particular validation error would occur, head to Validation Error: Value is not valid. This is namely a strong hint that your model is broken — even though you never intented to update the model, it can still have its consequences elsewhere in the chain.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks, however I get disabled input component when I try to ajax update it. I need to disable it only when form is submitted not when it is updated via ajax . – Rajat Gupta Sep 30 '14 at 19:27