1

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
  • 2,151
  • 10
  • 27
  • 45

2 Answers2

6

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.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • Thanks BalusC. readonly="true" did not work. disabled="true" worked. Please edit, I will mark it as correct. – gekrish Jun 23 '10 at 11:57
  • 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. – BalusC Jun 23 '10 at 12:11
  • I am using like this, and now the values are not submitted!!! – gekrish Jun 24 '10 at 00:22
  • 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? – gekrish Jun 24 '10 at 01:02
  • 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. – BalusC Jun 24 '10 at 03:03
  • 1
    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. – gekrish Jun 26 '10 at 11:43
1

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