0

Initially a button is disabled, and I want it to get enabled when I select a row in the datatable, but the listener is not working and I can't find the problem...

This is how the xhtml file looks like:

<h:form id="form" class="formulario">
        ...
        <p:dataTable value="#{queryBean.offs}" var="offer" selection="#{queryBean.oferta}" rowKey="#{offer.offerNumber}" tableStyle="width:auto" >
                <f:facet name="header">Ofertas disponibles</f:facet>

                <p:ajax event="rowSelect" listener="#{queryBean.rowSelected}" />

                ...

        </p:dataTable>

            <center><br/>
            <h:commandButton id="botonReserva" value="Reservar" disabled="true" >
                <p:ajax process="form" update="form" resetValues="true" />
            </h:commandButton>

                ...
            </center>
</h:form>

And this is the bean's listener

...

public void rowSelected(SelectEvent selectEvent) {
    System.out.println("Working");
    //Not printing anything
}

...

I know I'm not updating the button but it is because it doesn't work, so first I want to know how to solve this. After I solve the problem I would know how to enable the button.

What could be the problem?

SOLUTION: It was because I was using a datatable with radio buttons, and I should have used event="rowSelectRadio" instead of event="rowSelect"

AwesomeGuy
  • 537
  • 1
  • 6
  • 17
  • Are you sure it's not printing anything? If you're running with an application server as is typical, the console output may, or may not be logged. If it is logged it may not be to a place you expect. Perhaps try creating a file in your rowSelected method instead. – Sam Dec 12 '17 at 15:55
  • @Sam i'll try, but other prints in other methods work – AwesomeGuy Dec 12 '17 at 15:58
  • Then that's not it. – Sam Dec 12 '17 at 15:59
  • Maybe add to the form and add update=":form:messages" as an attribute to the ajax element. May give you some more logging to work from – Sam Dec 12 '17 at 16:04
  • read all this: https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Dec 12 '17 at 17:51
  • @Sam nothing happens – AwesomeGuy Dec 12 '17 at 20:40
  • @Kukeltje I read it and it didn't help. I don't know what's wrong... I'm using session scope, it doesn't matter right? – AwesomeGuy Dec 13 '17 at 14:20
  • IF you have the 'wrong' sessionscoped annotation it does matter... – Kukeltje Dec 14 '17 at 19:00
  • @Kukeltje sorry but I don't understand what you mean – AwesomeGuy Dec 14 '17 at 22:16
  • https://stackoverflow.com/questions/15057564/why-are-there-different-bean-management-annotations – Kukeltje Dec 14 '17 at 22:48
  • Solved it!! It was because I was using a datatable with radio buttons, and I should have used `event="rowSelectRadio"` instead of `event="rowSelect"` ... My bad – AwesomeGuy Dec 15 '17 at 15:07

0 Answers0