我正在使用commandButton时遇到问题,仅当类型为submit时才有效。请问是否有解决方法?以下代码非常简单,旨在说明我所需要的内容。test()方法没有被执行,而runSubmit方法已成功执行。
我需要在不进行提交的情况下执行test方法,因为原始页面具有在提交期间执行的验证,而test()方法必须在提交之前作为预操作执行。
我正在使用PrimeFaces 4.0、JDK 7、Tomcat 6和JSF 2.0(Apache),不过我认为Mojarra也会发生这种情况。
SESSION:
package com.andre.bean;
public class AndreBean {
public void runSubmit() {
System.out.println("Submit executed");
}
public String test() {
System.out.println("Not submit executed");
return "true";
}
}
XHTML
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:form id="test">
<p:commandButton id="ns" value="not submit" type="button" action="#{andreBean.test}" ajax="false"></p:commandButton>
<p:commandButton id="s" value="submit" action="#{andreBean.runSubmit}"></p:commandButton>
</h:form>
</html>
非常感谢
Andre