Commandbutton仅在第二次点击时才起作用,直到< h:selectBooleanCheckbox>在HashMap上被删除 [英] Commandbutton works only on second click until a <h:selectBooleanCheckbox> on a HashMap is removed

查看:151
本文介绍了Commandbutton仅在第二次点击时才起作用,直到< h:selectBooleanCheckbox>在HashMap上被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 2.2.9,我有以下dataTable和buttons:

pre $ < h:commandButton id =commandButtonRemoverSelected
actionListener =#{managedBeanName.removeSelected()}
class =btn btn-primaryvalue =Sim>
< / h:commandButton>

< h:dataTable var =beanvalue =#{managedBeanName.beans}styleClass =table table-hover
binding =#{managedBeanName.dataTable} >
< h:列headerClass =smallColumn>
< f:facet name =header>
< h:selectBooleanCheckbox valueChangeListener =#{managedBeanName.selectAll}>
< / h:selectBooleanCheckbox>
< / f:facet>
< h:selectBooleanCheckbox value =#{managedBeanName.registrosSelecionados [bean]}/>
< / h:栏>

< / h:dataTable>

按钮commandButtonRemoverSelected在第二次点击时调用actionListener。当我从datatabe中删除以下行时,一切正常(第一次单击时调用commandButton):

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

因此,我的managedBean有一个名为'registrosSelecionados'的MAP,它应该存储一对Bean,Boolean 。请参阅:

 私人地图< Bean,布尔> registrosSelecionados = new HashMap< Bean,Boolean>(); 


解决方案

解决方案



我用解决方法解决了问题,我会分享这个:

1 - I注意到每个第一个commandButton都会调用'getRegistrosSelecionados()',actionListener则不会。所以我想JSF正在处理getRegistrosSelecionados()并且不处理actionListener,我不知道为什么,这是真正的问题。在第二次点击actionListener被处理,因为所有复选框已经发送到ManagedBean,在第一次点击。

2 - 所以,我的解决方法是强制每个点击复选框调用JSF请求并且不要等待commandButton提交。以这种方式当单击commandButton时,所有复选框都被处理。

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

我的复选框收到ajax只执行自己并呈现自己,当我点击commandButton时,我只需要执行commandButton并再次呈现表单:

 < h:commandButton id =commandButtonRemoverSelected
actionListener = #{cc.attrs.managedBeanName.removeSelected()}
class =btn btn-primaryvalue =Sim>
< / h:commandButton>

这种解决方法适用于我,因为我没有找到针对此问题的更好解决方案。 p>

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>();

解决方案

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.

这篇关于Commandbutton仅在第二次点击时才起作用,直到&lt; h:selectBooleanCheckbox&gt;在HashMap上被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆