JSF只读inputText问题 [英] JSF readonly inputText issue
问题描述
如果设置了required="true"
,则readonly inputText无效.
Readonly inputText doesn't validate if required="true"
is set.
<h:panelGrid columns="3" id="townShipPanelGroup">
<p:inputText value="#{AddNewLifeProposalActionBean.beneficiariesInfoDTO.residentAddress.township == null ? '' : AddNewLifeProposalActionBean.beneficiariesInfoDTO.residentAddress.township.name}"
style="width:250px;margin-left:-4px;" id="townShip" readonly="true">
<f:validateLength maximum="36"/>
</p:inputText>
<p:commandLink immediate="true" oncomplete="selectTownShipDialog.show()" id="selectTownShipDialogLink" action="#{AddNewLifeProposalActionBean.loadTownshipList()}">
<h:graphicImage url="/images/search.png" style="height:30px;width:30px"/>
</p:commandLink>
</h:panelGrid>
推荐答案
这符合预期.出于所有意图和目的,JSF不会在整个请求生命周期中评估被指定为readonly="true"
的值.建议完成此操作的方法是在RENDER_RESPONSE
阶段将值设为只读,在该阶段将视图呈现给用户.在任何其他阶段,您都希望JSF运行时将输入字段解释为可写的.为此,您可以使用:
This is behaving as expected. For all intents and purposes, JSF doesn't evaluate a value that is designated as readonly="true"
throughout the request lifecycle. The recommended way to get this done is to make the value readonly during the RENDER_RESPONSE
phase, where the view is being presented to the user. During any other phase, you want the JSF runtime to interpret the input field as writeable. For that purpose, you can use:
<p:inputText value="#{AddNewLifeProposalActionBean.beneficiariesInfoDTO.residentAddress.township == null ? '' : AddNewLifeProposalActionBean.beneficiariesInfoDTO.residentAddress.township.name}"
style="width:250px;margin-left:-4px;" id="townShip" readonly="#{facesContext.renderResponse}">
<f:validateLength maximum="36"/>
</p:inputText>
这样,readonly
属性仅在用户查看页面时才为true.对于所有其他阶段,JSF运行时将认为该字段是可写的,因此,将在该字段上进行验证
This way, the readonly
property is only true when the user is viewing the page. For all other phases, the JSF runtime will see the field as writeable and as a result, validation will be carried out on the field
参考文献:
- JSF Readonly input not validated
- How to detect if a previous redirect was invoked?
- jsf (richfaces) readonly input text validation
这篇关于JSF只读inputText问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!