The list passed to the select's value is of Integer type.
<p:selectManyMenu id="estabelecimentos" value="#{questionarioMB.estabelecimentosIds}" var="e" converter="#{estabelecimentoConverter}" style="width:100%" filter="true" filterMatchMode="contains" showCheckbox="true">
<f:selectItems value="#{questionarioMB.estabelecimentos}" var="estabelecimento" itemValue="#{estabelecimento}" itemLabel="#{estabelecimento.nomefantasia}" />
<p:column>
<h:outputText value="#{estabelecimentoMB.getIdentificadorByEstabelecimentoId(e.id)}" />
</p:column>
<p:column>
<h:outputText value="#{e.nomefantasia}" />
</p:column>
</p:selectManyMenu>
Netbeans cannot find the attributes in the outputTexts ("unknown property") and the line throwing the exception is the following:
this.estabelecimentosIds.parallelStream().forEach((Integer id) -> {
this.questionarioBean.insertQuestionarioHasEstabelecimento(this.questionarioBean.getLastId() + 1, id);
});
The converter:
@Named
public class EstabelecimentoConverter implements Converter {
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
if (value != null && value.trim().length() > 0) {
try {
EstabelecimentoMB estabelecimentoMB = (EstabelecimentoMB) fc.getExternalContext().getApplicationMap().get("estabelecimentoMB");
return estabelecimentoMB.getEstabelecimentos().get(Integer.parseInt(value));
} catch (NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro de Conversão", "Estabelecimento inválido."));
}
} else {
return null;
}
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
if (o != null) {
return String.valueOf(((Estabelecimento) o).getId());
} else {
return null;
}
}
}
P.S.: I can't use the field tradingName
because it can be repeated in table establishment
, so I must use the "id" to differentiate them. The first column has the identifier for that establishment (in another table, "client_has_establishment", and can be repeated as well - but not for the same client_id
).