user728453
user728453

Reputation: 13

JSF Life Cycle (Validation)

I have a JSF page with an element which has attribute of required=true and disabled, I want to trigger the validation on that specific element. What I did is submitting it using <h:commandButton>, on the onclick event, I remove the disabled attribute, but after the page renders the validation error doesnt show up. Anyone knows why?

<h:inputText id="myInput" required="true" disabled="disabled" />
<h:commandButton id="saveButton" action="#{myBean.saveDetail}">

<script type="text/javascript">
  document.getElementById('saveButton').onclick = function() {
     document.getElementById('myInput').removeAttribute('disabled');
  }
</script>

Upvotes: 1

Views: 577

Answers (1)

Adam
Adam

Reputation: 5070

There are a couple of problems here:

1.The disabled attribute should be boolean on the inputText.

2.Disabled attribute means:

Flag indicating that this element must never receive focus or be included in a subsequent submit.

So no validators will run on it.

3.You can't change the h:inputText's disabled attribute on the client side, it would be a security problem in JSF if you could.

Upvotes: 1

Related Questions