Primefaces widgetvar函数在我使用ajax调用提交时不起作用



我正在尝试根据单击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>

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

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

最新更新