我正在使用PrimeFaces autocomplete
组件multiple="true"
。此组件在添加时工作正常。但是当我尝试进行任何更新时,它始终会给出验证错误,说明即使值正确显示,该值也是必需的。这是我的代码
<p:autoComplete id="entitySpecId" multiple="true" inputStyle="width: 100%" queryDelay="500"
size="50" value="#{equipTemplateBean.selectedEntities}"
completeMethod="#{equipTemplateBean.completeAssnEntity}" var="spec"
itemLabel="#{spec.specName}" itemValue="#{spec}" converter="specificationConverter"
required="true">
<p:ajax event="itemSelect" listener="#{equipTemplateBean.entityMultiSelect}" update="messagePanel" />
<p:column>
<h:outputText value="#{spec.specName}" />
</p:column>
</p:autoComplete>
请帮我解决这个问题
SpecificationConverter.java
的代码public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if (value != null && value.trim().length() > 0) {
EquipmentTemplateBean templateBean = null;
try {
if (fc != null) {
ELContext elContext = fc.getELContext();
templateBean = (EquipmentTemplateBean) elContext.getELResolver().getValue(elContext, null, "equipTemplateBean");
}
if (null != templateBean && null != templateBean.getAllSpecsList()) {
for (Specification spec : templateBean.getAllSpecsList()) {
if (null != spec && Integer.parseInt(value) == spec.getSpecificationId().intValue()) {
return spec;
}
}
return null;
} else {
return null;
}
} catch (NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid entity."));
}
} else {
return null;
}
}