Disable text in JSF textbox

I have a simple form with selectOneMenu and textarea that I want to disable if the selected value is selected in select (onchange event). How can I achieve this?

<p:selectOneMenu id="way" value="" onchange="">
    <f:selectItem value="0" itemLabel="#{texts.post}" />
    <f:selectItem value="1" itemLabel="#{texts.pickup}" />

<h:outputLabel for="address" value="#{texts.address}" />
<p:inputTextarea id="address" widgetVar="addressTextarea" value="" />



source to share

2 answers

I don't think there is a public interface for inputTextarea, but you can get the clientId and disable the html textarea, or use jquery to disable it entirely:

<p:selectOneMenu onchange="if(this.value == 1) { $(addressTextarea.input.attr('disabled', 'true)); $(addressTextarea.input.addClass('ui-state-disabled')) }">


Or using ajax you can use:

<p:selectOneMenu id="way" value="#{selectValue}">
    <f:selectItem value="0" itemLabel="#{texts.post}" />
    <p:ajax event="change" update="address"/>

<p:inputTextarea id="address" widgetVar="addressTextarea" value="" disabled="#{selectValue == 0}"/>




You can try this:

<p:inputTextarea id="address" widgetVar="addressTextareaWV" />

<p:selectOneMenu id="way" onchange="disableComponent()"/>

<script language="javascript" type="text/javascript">
    function disableComponent() {

    function enableComponent() {




All Articles