Data in disappears when command button is clicked

前端 未结 1 1613
陌清茗
陌清茗 2020-12-09 22:50

I am using JSF 1.1. I have a JSF page with a request scoped bean and a readonly input field.



        
相关标签:
1条回答
  • 2020-12-09 23:10

    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.

    0 讨论(0)
提交回复
热议问题