【发布时间】:2013-11-02 00:41:31
【问题描述】:
我遇到了 commandButton 的问题,它仅在类型为提交时才有效。有人可以看看并让我知道是否有解决方案吗?下面的代码非常简单,并且确实有说明我需要什么的建议。方法 test() 未执行。方法runSubmit执行成功。
我需要在没有提交的情况下执行测试方法,因为原始页面确实在提交期间执行了验证,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>
非常感谢 安德烈
【问题讨论】:
-
尝试使用 actionListener="#{andreBean.test()}" process="@this :test" ..
-
感谢您的回复,刚刚试了,还是不行,结果和以前一样。但是,在测试方法中使用括号时出现解析错误,仅适用于“andreBean.test”。我读到了一些与 EL 相关的限制,我需要在这个项目中使用 Tomcat 版本 6,因此可用的 EL 最高为 2.1。提前感谢您提供更多信息。
-
如果您不想提交完整的表单,则必须使用 AJAX...
-
我认为我有一个限制,因为我需要使用 Tomcat 6。当我在我的方法 (andreBean.test()) 中使用括号时,我得到一个解析错误,当我删除括号时,我收到一个消息说“andreBean”中不存在属性“test”...死锁:(我在commandButton中使用了ajax,如下所示,使用括号而不使用:
其他建议? -
您不需要 f:ajax。您可以在 p:commandButton 上设置 ajax="true" (这是默认值),然后使用 actionListener="#{andreBean.test}"
标签: jsf primefaces