1

我有一个嵌入在向导中的选择列表,如果在目标中选择了某些东西,它应该只继续下一步。它可以工作,但问题是验证在渲染时触发:用户看到的第一件事是错误消息,甚至在点击“下一步”按钮之前。有什么办法可以关闭它吗?

这是xhtml:

<p:pickList id="pickList" value="#{someBean.Rules}"
            var="rule"
            itemLabel="#{rule.name}"
            itemValue="#{rule}"
            converter="accountingObjectConverter"
            responsive="true"
            showSourceFilter="true" showTargetFilter="true"
            filterMatchMode="contains"
            style="width: 100%"
            validator="myValidator"
        >

    <f:facet name="sourceCaption">Select</f:facet>
    <f:facet name="targetCaption">Selected</f:facet>

    <p:column>
        <h:outputText value="#{rule.name}"/>
    </p:column>
</p:pickList>

这是我的验证器:

  @FacesValidator("myValidator")
  public class MyValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        checkForEmptyFields(context, component, (DualListModel) value);
    }

    private void checkForEmptyFields(FacesContext context, UIComponent component, DualListModel value) {
        if ( value.getTarget().size() == 0) {
            ((UIInput) component).setValid(false);
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error: must select at least one item", ""));
        }
    }
}

感谢您的时间。

编辑:这是向导:

<h:form id="mainForm">
    <p:wizard id="ruleWizard" widgetVar="ruleWiz"
              flowListener="#{aBeanL.flowListener}"
              nextLabel="next"
              backLabel="back">

        <p:tab id="queryTab" title="rules">
            <ui:include src="theXhtmlAbove.xhtml"/>
        </p:tab>
        *some tabs*

    </p:wizard>
</h:form>
4

0 回答 0