Java 在ajax之前执行actionListener?
如何在ajax请求之前执行actionListenerJava 在ajax之前执行actionListener?,java,ajax,jsf,Java,Ajax,Jsf,如何在ajax请求之前执行actionListener <h:commandButton actionListener=.. action=..> <f:ajax render="test"> </h:commandButton> 我可以做些什么更改,以便在f:ajax之前执行actionListener方法 完整示例: <h:form> <h:commandButton value="test" actionListener="
<h:commandButton actionListener=.. action=..>
<f:ajax render="test">
</h:commandButton>
我可以做些什么更改,以便在f:ajax之前执行actionListener方法
完整示例:
<h:form>
<h:commandButton value="test" actionListener="#{bean.toggleProgress}" action="#{bean.do()}" >
<f:ajax execute="@form" render="progress" />
</h:commandButton>
<h:panelGroup id="progress" >
<h:outputText rendered="#{bean.progress}" />
</h:panelGroup>
</h:form>
class Bean {
private progress = false;
public boolean isProgress() {
System.out.println("in: ajax")
return progress;
}
public toggleProgress(ActionEvent e) {
System.out.println("in: actionListener")
progress = true;
}
public void do() {
System.out.println("in: action")
}
}
你所描述的不是真的。这一定是一种误解。我认为是后者,因为您没有任何
。也许你把JavaScriptonclick
和Java混淆了?确实如此!上面用完整的示例进行了编辑。在表单提交期间,系统是否从中退出?您确定第一行不是来自初始GET请求吗?是的,初始GET请求会另外生成一个“in:ajax”。但是上面的sysout只是来自提交!嗯,我从来没见过。您使用的是什么JSF impl/版本?顺便说一下,您的完整示例未编译,但这将是粗心大意:/
<h:form>
<h:commandButton value="test" actionListener="#{bean.toggleProgress}" action="#{bean.do()}" >
<f:ajax execute="@form" render="progress" />
</h:commandButton>
<h:panelGroup id="progress" >
<h:outputText rendered="#{bean.progress}" />
</h:panelGroup>
</h:form>
class Bean {
private progress = false;
public boolean isProgress() {
System.out.println("in: ajax")
return progress;
}
public toggleProgress(ActionEvent e) {
System.out.println("in: actionListener")
progress = true;
}
public void do() {
System.out.println("in: action")
}
}
in: ajax
in: actionListener
in: action