1

I'm working with JSF 2.2.9, i have the following dataTable and buttons:

<h:commandButton id="commandButtonRemoverSelected"
                        actionListener="#{managedBeanName.removeSelected()}"
                        class="btn btn-primary" value="Sim">
                    </h:commandButton>

    <h:dataTable var="bean" value="#{managedBeanName.beans}" styleClass="table table-hover" 
            binding="#{managedBeanName.dataTable}">
                <h:column headerClass="smallColumn">
                    <f:facet name="header">
                        <h:selectBooleanCheckbox valueChangeListener="#{managedBeanName.selectAll}">
                            <f:ajax execute="@form" render="@all" />
                        </h:selectBooleanCheckbox>
                    </f:facet>
                    <h:selectBooleanCheckbox value="#{managedBeanName.registrosSelecionados[bean]}" />
                </h:column>

            </h:dataTable>

The button "commandButtonRemoverSelected" just call actionListener on second click. When i remove the following line from datatabe everything works fine (the commandButton is called on first click):

<h:selectBooleanCheckbox value="#{managedBeanName.registrosSelecionados[bean]}" />

So, my managedBean have a MAP called 'registrosSelecionados' that should store a pair "Bean,Boolean". See:

private Map<Bean, Boolean> registrosSelecionados = new HashMap<Bean, Boolean>();
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Shelly
  • 1,035
  • 5
  • 27
  • 51
  • Might be a bug with the viewstate. What's your current viewstate setting (try `SERVER`)? Also, you're not doing any business logic in the getter for `registrosSelecionados` are you? – kolossus Feb 05 '15 at 07:06
  • At least, `binding="#{someTooBroadScopedBean.component}` and `render="@all"` are scary. Get rid of them and retry. – BalusC Feb 05 '15 at 10:40
  • @BlausC, I need use 'binding' to get my selected row in ManagedBean, how can i get rid of them if i need them ? PS: I already tried remove the binding but the problem continue. – Shelly Feb 05 '15 at 15:39
  • @kolossus, my viewstate is 'server'. And i'm not doing any business logic in getter. – Shelly Feb 05 '15 at 15:47

1 Answers1

1

SOLUTION

I solved the problem with a workaround and i would share this:

1 - I noted that every first commandButton click the 'getRegistrosSelecionados()' is called and actionListener don't. So i imagine that JSF is processing getRegistrosSelecionados() and don't processing actionListener, i don't know why and this is the real problem. In second click the actionListener is processed because all checkboxs already sent to ManagedBean, in first click.

2 - So, my workaround is force that each click in checkbox call JSF request and don't wait for commandButton submit. In this way when commandButton is clicked all checkbox was processed.

<h:selectBooleanCheckbox value="#{cc.attrs.managedBeanName.registrosSelecionados[bean]}">
                  <f:ajax execute="@this" render="@this" />
                </h:selectBooleanCheckbox>

My checkbox received the ajax to execute only itself and render itself, when i click in commandButton i just need execute the commandButton and render the form again:

<h:commandButton id="commandButtonRemoverSelected"
                        actionListener="#{cc.attrs.managedBeanName.removeSelected()}"
                        class="btn btn-primary" value="Sim">
                        <f:ajax execute="@this" render="@form" />
                    </h:commandButton>

This workaround works for me, as i didn't found a better solution for this problem.

Shelly
  • 1,035
  • 5
  • 27
  • 51
  • Thank you. Wasted a day to understand what is going on. The easiest way is to use the Primefaces. But in this case i also want to use my styles with and not a – Taras Vovkovych Mar 22 '17 at 16:22