-2
       <h:panelGrid id="userActivationGrid" columns="1">
            <p:selectOneRadio value="#{user.activationMode}" layout="pageDirection" immediate="true" >
                <f:selectItem itemLabel="${adminmsgs['create.avtivateMode.button.label']}" itemValue="${adminmsgs['create.avtivateMode.button.itemvalue.label']}"  />
                <f:selectItem itemLabel="${adminmsgs['create.avtivateMode1.button.label']}" itemValue="${adminmsgs['create.avtivateMode1.button.itemvalue.label']}"  />
                <f:ajax event="change" render="userActivationGrid" /> 
                <f:ajax event="click" listener="#{user.tempPassword()}"/>
            </p:selectOneRadio>
            <p:spacer width="10"/>
            <h:panelGrid id="manualActivationGrid" rendered="#{user.manualActivation}" columns="3">
                <h:outputLabel>#{adminmsgs['create.manualActivation.text.label']}</h:outputLabel>
                <p:inputText id="userName" immediate="true" required="true" value="#{user.userName}" requiredMessage="UserName Should Be Entered" validatorMessage="Username Should Be alphanumeric"/>
                <h:message id="userNameMsg" for="userName" />
                <h:outputLabel>#{adminmsgs['create.manualActivation1.text.label']}</h:outputLabel>
                <p:password id="password" immediate="true" required="true" validatorMessage="password should be minimum 5 character" requiredMessage="Password is Mandatory"/>
                <h:message id="passwordMsg" for="password" />
            </h:panelGrid>
        </h:panelGrid>

我正在使用两个单选按钮,如果我选择单选按钮,用户名和密码应该验证,否则它不会被验证。请帮助我提前感谢

4

1 回答 1

1

我建议像这样添加f:validateRegex标签 userNamepassword输入:

<p:inputText id="userName" immediate="true" required="true" value="#{user.userName}" requiredMessage="UserName Should Be Entered" validatorMessage="Username Should Be alphanumeric">        
  <f:validateRegex pattern="[_A-Za-z0-9]+" disabled="#{user.validationDisabled}" />
</p:inputText>

validationDisabled属性使用您的单选按钮值来确定是否需要验证。有关 Primefaces + JSF 验证器的更多示例,请参见此处

于 2013-05-13T19:57:34.277 回答