Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF2-必需复选框_Jsf_Jsf 2 - Fatal编程技术网

JSF2-必需复选框

JSF2-必需复选框,jsf,jsf-2,Jsf,Jsf 2,我正在尝试编写一个必需的复选框,用于显示用户必须接受的条款和条件。我实际上不需要任何支持bean,我只需要确保用户选中该框 我尝试了以下方法,但似乎不起作用: JSF: 感谢BalusC提供了所需的CheckboxValidator代码,它到底是如何失败的?首先,是否命中了validate()方法?顺便说一句,我可以使用。确实调用了validate方法,但我需要进一步调试。它与h:selectBooleanCheckbox一起工作,因此它特定于primefaces。 <p:selectBo

我正在尝试编写一个必需的复选框,用于显示用户必须接受的条款和条件。我实际上不需要任何支持bean,我只需要确保用户选中该框

我尝试了以下方法,但似乎不起作用:

JSF:


感谢BalusC提供了所需的CheckboxValidator代码,它到底是如何失败的?首先,是否命中了
validate()
方法?顺便说一句,我可以使用
。确实调用了validate方法,但我需要进一步调试。它与h:selectBooleanCheckbox一起工作,因此它特定于primefaces。
<p:selectBooleanCheckbox required="true"> <f:validator validatorId="RequiredCheckboxValidator" /></p:selectBooleanCheckbox>
@FacesValidator("RequiredCheckboxValidator")
public class RequiredCheckboxValidator implements Validator {

    public void validate(FacesContext context, UIComponent component, Object value)
        throws ValidatorException
    {
        if (value.equals(Boolean.FALSE)) {
            String requiredMessage = ((UIInput) component).getRequiredMessage();

            if (requiredMessage == null) {
                Object label = component.getAttributes().get("label");
                if (label == null || (label instanceof String && ((String) label).length() == 0)) {
                    label = component.getValueExpression("label");
                }
                if (label == null) {
                    label = component.getClientId(context);
                }
                requiredMessage = MessageFormat.format(UIInput.REQUIRED_MESSAGE_ID, label);
            }

            throw new ValidatorException(
                new FacesMessage(FacesMessage.SEVERITY_ERROR, requiredMessage, requiredMessage));
        }
    }

}