2
votes

Well, i have a method in my ManagedBean that reload my bean. this is my XHTML code:

<h:outputText value="Contrato: *" styleClass="bold" />
                        <p:selectOneMenu converter="entityConverter"
                            disabled="#{layoutExportacaoMB.bean.id != null}"
                            value="#{layoutExportacaoMB.contratoSelecionado}"
                            effect="fade" required="true" filter="true" filterMatchMode="contains"
                            requiredMessage="O Contrato é obrigatório">
                            <f:selectItem itemLabel="Selecione um Contrato" itemValue="" />
                            <f:selectItems value="#{layoutExportacaoMB.contratos}"
                                var="contrato"
                                itemLabel="#{contrato.numeroContratoFormatadoECliente}"
                                itemValue="#{contrato}" />
                            <p:ajax event="change" update="produtos" listener="#{layoutExportacaoMB.carregarProdutosContrato}" />
                        </p:selectOneMenu>

When user change this item the method bellow must be called but this don't happens. I know that ajax event change is fired because my component "produtos" is updated.

See my method on ManagedBean:

public void carregarProdutosContrato(){
    logger.info("Carregando contrato "+contratoSelecionado.getNumeroContratoFormatado());
    contratoSelecionado = (Contrato) getBoPadrao().findByNamedQuery(Contrato.FIND_COM_PRODUTOS_BY_ID, 
        new NamedParams("id", contratoSelecionado.getId()));
    }

SOLUTION:

Solution is more easy that i thought, just use listener with "()" in the end, look:

                    <p:ajax event="change" update="produtos" listener="#{layoutExportacaoMB.carregarProdutosContrato()}" />

Worked for me.

2
There's a lot of noise in the code. Most likely a conversion/validation error is causing the form submission to choke. place a <p:messages/> component on your page to see possible errors - kolossus
Bad solution. You should have added the correct event to the method parameters/signature on the java side instead of adding () in the call in tge xhtml. Secondly, solutions belong in Answers, not via an edit in the question - Kukeltje

2 Answers

6
votes

Try the following :):

  1. Make sure your <p:selectOneMenu> is inside a <h:form>.
  2. Add process="@this" attribute to your <p:ajax>.
  3. Add a <p:growl> with globalOnly="false" and autoUpdate="true" may help you identify any validation and conversion errors.
-1
votes

For me the problem was that the object value

<p:selectOneMenu value="#{userMB.getOneObject()}" ...

was object that wasn't connected to the managed bean somehow (here I get it with function call). The value for the selectOneMenu should be property of the managed bean or at least something kept in some jsf scope. That is my understanding of what happened. Hope it helps.

<p:selectOneMenu value="#{userMB.oneObject}" ...