如果我使用ajax调用提交,Primefaces widgetvar函数将不起作用

时间:2018-09-24 05:50:02

标签: jsf primefaces

我正在尝试基于xhtml中另一个按钮的单击来启用/禁用一个按钮。 当我使用ajax调用时,这不起作用,但是如果禁用了ajax,则可以。

我如何进行这项工作。

xhtml(此方法可以正常工作,并且按钮可以禁用几秒钟,但是页面会加载,并且再次启用了按钮)

<p:commandButton id="generateBtn" value="Generate Text"
                action="#{decisionTreeBean.generateText}" styleClass="generateBtn" widgetVar="gb"
                update=":#{p:component('decisionNotes')}" >
            </p:commandButton>

            <p:commandButton id="clearBtn" value="Clear"
                action="#{decisionTreeBean.clearText}"  styleClass="clearBtn" widgetVar="cb"
                update=":#{p:component('decisionNotes')} :#{p:component('searchForm')}" ajax="false">
            </p:commandButton>

xhtml(根本不起作用)

<p:commandButton id="generateBtn" value="Generate Text"
                action="#{decisionTreeBean.generateText}" styleClass="generateBtn" widgetVar="gb"
                update=":#{p:component('decisionNotes')}" >
            </p:commandButton>

            <p:commandButton id="clearBtn" value="Clear"
                action="#{decisionTreeBean.clearText}"  styleClass="clearBtn" widgetVar="cb"
                update=":#{p:component('decisionNotes')} :#{p:component('searchForm')}">
            </p:commandButton>

jQuery

<SCRIPT type="text/javascript">
            jQuery(document).ready(function() {
                if (top.frames.length != 0) {
                    top.location = self.document.location;
                }
                jQuery(".clearBtn").click(function(event){
                    PF('gb').disable(); // works without ajax
                });
            });
</SCRIPT>

1 个答案:

答案 0 :(得分:0)

尝试将您的generateButton添加到clearButton的更新子句中。

如果我不得不猜测它在非ajax版本中工作的原因是您实际上在更新站点,那么generateButton会接收到他被禁用的调用(但是随后该站点被重新加载,因此状态被重置了) )。由于您没有在Ajax版本中更新该按钮,因此该按钮永远不会更新,因此不会被禁用。