How to stop the user in entering text for h:inputText?

jsf
18,394

Solution 1

The readonly="true" should suit your requirements. The text will be uneditable and the value will be submitted to the server.

The disabled="true" don't suit your requirements. The text will indeed be uneditable, but the value won't be submitted to the server.

Note that when you use them both, then the value won't be submitted at all. Also when there's a rendered attribute on it or one of its parents which evaluates to false during form submit, then the value won't be gathered during apply request values phase of the form submit request.

Solution 2

Actually, readonly = "true" doesn't submit value to server, I suggest readonly= "#{facesContext.renderResponse}", it works well for me

Share:
18,394
gekrish
Author by

gekrish

Updated on November 19, 2022

Comments

  • gekrish
    gekrish about 1 year

    I am using JSF 1.2 - My Faces Implementation. I have a form , I use h:inputText to display few values. There are 2 input boxes which should not be edited but shown to the user and should be submitted to the server when the submit it clicked. I tried readonly="true" and disabled="true", both did not solve the purpose! Any suggestions?

  • gekrish
    gekrish over 13 years
    Thanks BalusC. readonly="true" did not work. disabled="true" worked. Please edit, I will mark it as correct.
  • BalusC
    BalusC over 13 years
    No, readonly should suit your requirements. Aren't you using some bean property for that which should be retained in the subsequent request? E.g. readonly="#{bean.readonly}"? If so, you know the answer. If not, then you need to elaborate "did not work" in more detail. Explain it in developer's perspective, not in enduser's perspective.
  • gekrish
    gekrish over 13 years
    <h:inputText styleClass="disabledfield" size="3" disabled="true" id="editIBD" value="#{someBean.someValue}"> I am using like this, and now the values are not submitted!!!
  • gekrish
    gekrish over 13 years
    I tried as you suggesed defaulting readOnly to true in the Bean.It does not help. FYI , I am populating the values of these fields using Javascript in the front end and I could see them when populated in the screen but in the debug JSF Life cycle phases-sysouts(INVOKE APPLICATION), I could not!!! Whats wrong?
  • BalusC
    BalusC over 13 years
    If disabled="true" then the value will indeed never be submitted as I stated in my answer. Changing it to disabled="false" in JS is not enough. It's still disabled="true" in JSF component tree in the server side. You need to change it in the server side as well. I.e. change the value using JSF/Java, not JS.
  • gekrish
    gekrish over 13 years
    I wasn't able to use either of them successfully. For Now , I have corresponding hiddenInput and make the non-Hidden as readonly="true" , that way i get the value in the server side and the user is not allowed to edit.