6

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}" />
5
  • 1
    set the disabled attribute to true
    – rags
    Sep 4, 2012 at 5:10
  • Sorry, I should not have used the word "disabled" as it can be interpreted as referring to the attribute disabled. What I mean is that I want it to be in a read-only state as described in the text above. Using the disabled attribute will mean that the value will not be posted.
    – javaMS
    Sep 4, 2012 at 5:46
  • That's interesting. How will the component behave? Will it still be posted? Also, what is the difference between pe:blockui and p:blockui and which one should I use?
    – javaMS
    Sep 4, 2012 at 8:15
  • I dont see how I can get this to work? It seems to be some functionality related to Ajax submission? I need to disable this field AFTER ajax submission indefinitely.
    – javaMS
    Sep 10, 2012 at 9:42
  • I want to make it blocked after I enter a value into a field, run an Ajax query, fetch information and populate all fields on the screen including the selectOneMenu field. I dont have a problem making all other fields readonly except the selectOneMenu which does not support read-only.
    – javaMS
    Sep 10, 2012 at 10:11

1 Answer 1

5

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 />.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.