10

只读 inputText 不验证是否required="true"已设置。

<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>
4

1 回答 1

17

这是按预期运行的。出于所有意图和目的,JSF 不会评估在readonly="true"整个请求生命周期中指定的值。完成此操作的推荐方法RENDER_RESPONSE是在向用户呈现视图的阶段将值设为只读。在任何其他阶段,您希望 JSF 运行时将输入字段解释为可写。为此,您可以使用:

<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属性仅在用户查看页面时为真。对于所有其他阶段,JSF 运行时会将字段视为可写字段,因此将对字段进行验证

参考:

于 2013-09-09T08:37:35.100 回答