0

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?

BicaBicudo
  • 307
  • 1
  • 8
  • 20
  • I am not good at primesfaces, but you said there is a validation message! If you have any validation error its normal that the action method will not be invoked – Tarik Feb 15 '15 at 00:37
  • Yes, the message is "the value (the type of the selectonemenu) is not valid" – BicaBicudo Feb 15 '15 at 01:13
  • What's abnormal then ? if validation don't succeed there will be no call to the action method, so what is the issue? do you want to know why you have this error or how to bypass the validation process? – Tarik Feb 15 '15 at 01:20
  • How I could debug this? – BicaBicudo Feb 15 '15 at 01:23
  • As i told you i am not good at primefaces but i will try if i can help, could you print the exact validation message you have – Tarik Feb 15 '15 at 01:25
  • Yes, but how I said, the only output in console is the sql sentence of the selectonemenu component. Interesting that the query does not specify the id in the where clause. But checking the source code, the items are ok. – BicaBicudo Feb 15 '15 at 01:29
  • Could you add the stack of the error and also the converter `tipoProfissionalConverter` – Tarik Feb 15 '15 at 01:32
  • The converter is above... – BicaBicudo Feb 15 '15 at 01:37
  • you can add a breakpoint in `return tipoProfissional;` if `tipoProfissional` is not null then it's not about conversion – Tarik Feb 15 '15 at 01:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/70937/discussion-between-bicabicudo-and-tarik). – BicaBicudo Feb 15 '15 at 01:43
  • Thank you Tarik. In fact, this was a difficult debug to me. Instead pass "new SelectItem(tipoProf.getId()", ... a little trick. Just "tipoProf" as first parameter. – BicaBicudo Feb 20 '15 at 23:58
  • Oh! so glad you fix it :) – Tarik Feb 21 '15 at 02:10

0 Answers0