我有一个嵌入在向导中的选项列表,只有在目标中选择了某些内容后才能进行下一步。它可以工作,但问题是验证会在渲染时触发:用户看到的第一件事就是错误信息,甚至在点击" next"按钮。有什么办法可以解决这个问题吗?
这是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", ""));
}
}
}
感谢您的时间。
编辑:这是wizzard:
<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>