How can I make Primefaces selectonemenu in disabled state?
I have read on this forum that this can be achieved by using a hidden field, however I do not understand how this can be implemented.
Make the <p:selectOneMenu>
disabled, and create a <p:inputText type="hidden" value="#{bean.property}" />
. The value
attribute must be the same as the <p:selectOneMenu>
. If necessary, use the same converter.
This way, the <p:selectOneMenu>
will be disabled to the user, but the value will be submitted by the hidden <p:inputText />
.
Remember that the hidden input is still a <p:inputText />
, and thus it needs to be updated when its value changes. Assign an ID to it, and make sure you add it to the update
of your <p:ajax />
.
javaMS
Updated on July 06, 2022Comments
-
javaMS almost 2 years
I need to use p:selectonemenu and make it disabled, i.e. it should be submitted during a post but it should be read-only. Please note that I do NOT want to use the disabled attribute as this will prevent posting.
I have read on this forum that this can be achieved by using a hidden field, however I do not understand how this can be implemented. I would appreciate if someone out there could provide me with some help in this regard.
<p:inputText id="cpr" value="#{customerbean.customer.cpr}"> <p:ajax event="change" listener="#{customerbean.fetchCustomerDatafromCBS}" update="nationality address passportno name nationality dob address mailingaddress gender mobileno landlineno otherno email maritalstatus nochildren" immediate="true" > <f:param name="cprNumber" value="#{customerbean.customer.cpr}"/> </p:ajax> <f:validator validatorId="cprValidator" /> </p:inputText> <p:selectOneMenu id="gender" value="#{customerbean.customer.gender}" required="!#{customerbean.disabled}" requiredMessage="#{text['validation.error.required.gender']}" disabled="#{customerbean.disabled}"> <f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" /> <f:selectItem itemLabel="Male" itemValue="Male" /> <f:selectItem itemLabel="Female" itemValue="Female" /> </p:selectOneMenu> <p:inputText type="hidden" value="#{customerbean.customer.gender}" />