I am using JSF 1.1. I have a JSF page with a request scoped bean and a readonly input field.
<h:inputText id="dt" value="#{bean.sdate}" readonly="#{bean.disable}" />
<a onclick="cal('dt');"><img src="fr.gif" border="0"></a>
When I set the input value using JavaScript and click on command button, then the data in input field disappears.
How is this caused and how can I solve it.
That’s because the property is set to
readonly. If this evaluatestrue, then JSF won’t process the submitted value and hence the model won’t be updated. If you want to set it toreadonlyon rendering the view and have JSF to process the submitted value, then you’d need to make it to evaluatetrueon render response phase only. You can useFacesContext#getRenderResponse()for this. You’d need to do this in yourisDisable()method.Note: in JSF2 you could access
FacesContext#getCurrentInstance()by#{facesContext}in the view as well, this saves some boilerplate in the model:Also note that when you’re using JSF2
<f:viewParam>, then this approach won’t work on GET requests anymore. See also Make a p:calendar readonly for the explanation and workaround.