JSF readonly inputText issue

前端 未结 1 1317
囚心锁ツ
囚心锁ツ 2020-12-29 11:45

Readonly inputText doesn\'t validate if required=\"true\" is set.


    

        
相关标签:
1条回答
  • 2020-12-29 12:30

    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>
    

    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

    References:

    • JSF Readonly input not validated
    • How to detect if a previous redirect was invoked?
    • jsf (richfaces) readonly input text validation
    0 讨论(0)
提交回复
热议问题