In my jsf web application, I'm using primefaces 5.0 and I'm in trouble when clicking the submit button (p:commandbutton
). The fact is, the request do not arrives at the controller and I have just a validation message at the top of the page, according to my p:message conditions.
Code that fills 'selectonemenu':
public List<SelectItem> getTipoProfissionalItems() throws Exception {
final List<TipoProfissional> listaTipoProf = TipoProfissionalService.listarTodos();
List<SelectItem> tipoProfissionalSelectItens = new ArrayList<>(listaTipoProf.size() + 1);
tipoProfissionalSelectItens.add(new SelectItem(null, "-- Selecione --"));
for (TipoProfissional tipoProf : listaTipoProf) {
tipoProfissionalSelectItens.add(new SelectItem(tipoProf.getId(), tipoProf.getDescricao()));
}
return tipoProfissionalSelectItens;
}
xhtml that renders the p:selectOneMenu
:
<p:outputLabel value="Tipo de profissional" for="tipoProf" />
<p:selectOneMenu id="tipoProf" converter="tipoProfissionalConverter" value="#{profissionalMB.tipoProfissional}">
<f:selectItems value="#{profissionalMB.tipoProfissionalItems}" />
</p:selectOneMenu>
I think the problem lies in the way the components are behaving at the time of request, like ajax, immediate tag or any other.
The p:commandButton
code:
<p:commandButton value="Gravar"
action="#{profissionalMB.gravar}"
update="@form"
title="#{msg.textoBotaoGravarProfissional}" />
The converter of the type 'TipoProfissional':
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
if (string == null || string.length() == 0) {
return null;
}
TipoProfissional tipoProfissional = null;
try {
tipoProfissional = TipoProfissionalService.localizar( Short.parseShort(string) );
} catch (Exception e) {
// todo
}
return tipoProfissional;
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
if (o == null || ("" + o).length() == 0) {
return null;
}
return o.toString();
}
Registering a 'preValidate' event, I saw that:
public void validateTipoProf(ComponentSystemEvent event) {
UIComponent components = event.getComponent();
UISelectOne selectOne = (UISelectOne) components.findComponent("tipoProf");
logger.info(selectOne.getValue()); // => empty string
logger.info(selectOne.getSubmittedValue()); // => the correct type value
}
There seems not to be a problem of implementation of the 'equals' method, except by the fact that 'equals' method have received the PK value, not the type described in this class. Would be?
In a 'Validator' created specifically for the component, the 'selectOneMenu' was filled out correctly.
The same sequence is persisted in the database table. What else can I check?