tags:

views:

31

answers:

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?

A: 

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
Thanks BalusC.readonly="true" did not work.disabled="true" worked. Please edit, I will mark it as correct.
gurupriyan.e
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
<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!!!
gurupriyan.e
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?
gurupriyan.e
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
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.
gurupriyan.e