Reputation: 159
hi as per my requirement there is one h:inputtext to find user. If user is found it populated first name, last name and email in corresponding h:inputtext which is disabled. but if not found that inputtext should become enabled and new details can be filled.
<h:inputText value="#{countryBean.usersDetailsDTO.eid}" id="eid" required="true" requiredMessage="Enter EID">
<f:ajax></f:ajax>
</h:inputText><h:message styleClass="msgStyle4" id="msgEid" for="eid"/>
</div>
<h:commandButton styleClass="search_btn" immediate="true">
<f:ajax listener="#{countryBean.getUserDetail}" render="empFName empLName empEmail" event="click" execute="@this" />
</h:commandButton>
<div class="clear"> </div>
<div class="form-field" style="margin-left:222px;">
first Name <h:inputText value="#{countryBean.usersDetailsDTO.firstName}" id="empFName" required="true" requiredMessage="Enter First Name">
<f:validator validatorId="nameValidation" />
</h:inputText><h:message styleClass="msgStyle4" id="msgfn" for="empFName"/>
</div>
<div class="clear"></div>
<div class="form-field" style="margin-left:10px;">
last name <h:inputText value="#{countryBean.usersDetailsDTO.lastName}" id="empLName" required="true" requiredMessage="Enter Last Name">
<f:validator validatorId="nameValidation" />
</h:inputText><h:message styleClass="msgStyle4" id="msgln" for="empLName"/>
</div><div class="clear"></div>
<div class="form-field" style="margin-left:10px;">
email<h:inputText value="#{countryBean.usersDetailsDTO.email}" id="empEmail" required="true" requiredMessage="Enter Email Address">
<f:validator validatorId="emailValidation" />
</h:inputText><h:message styleClass="msgStyle4" id="msgEmail" for="empEmail"/>
</div>
Upvotes: 3
Views: 21534
Reputation: 8161
You can use disabled
attribute on any time along with JSF EL to pass the Boolean value to disabled
attribute.
For example in your case If you want to disable any h:inputText
if first name is pre-populated then:
<h:inputText value="#{countryBean.usersDetailsDTO.email}" id="empEmail"
required="true" requiredMessage="Enter Email Address"
disabled="#{not(empty countryBean.usersDetailsDTO.firstName)}">
The above code will disable the Email
input text disabled
if firstname
is pre-populated.
Upvotes: 5
Reputation: 851
You can handle this on 2 ways:
1) You set the disable-tag of the inputText to a BackingBean-method like this:
<h:inputText ... disabled="#{countryBean.found}" ... />
2) Adding a valueChangeListener on the first inputText, so if it has a text, the others should be disabled.
Upvotes: 0