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 evaluates true
, then JSF won't process the submitted value and hence the model won't be updated. If you want to set it to readonly
on rendering the view and have JSF to process the submitted value, then you'd need to make it to evaluate true
on render response phase only. You can use FacesContext#getRenderResponse()
for this. You'd need to do this in your isDisable()
method.
public boolean isDisable() { // TODO: rename to isReadonly().
return FacesContext.getCurrentInstance().getRenderResponse();
}
Note: in JSF2 you could access FacesContext#getCurrentInstance()
by #{facesContext}
in the view as well, this saves some boilerplate in the model:
<h:inputText ... readonly="#{facesContext.renderResponse}" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With