jsFunction'当事件启动器在表单内时,s数据未定义
jsFunction's data is undefined when event starter is inside the form
这是我的情况:
我想测试是否链接javabean和xhtml,所以我使用richfaces,a4j:jsFunction来处理它。
我成功了——在某种程度上,活动的开始者必须在形式之外开火,所以太奇怪了
我的代码中有三个部分:xhtml、js、java
xhtml:
<button id="succeed" onclick="showMessage()"> succeed_test </button>
<!-- this is the succeeded button -->
<h:form id="form1" prependId="true" >
<button id="fail" onclick="showMessage()"> fail_test </button>
<!-- this is the failed button -->
<a4j:jsFunction
name="showMessage"
data="#{javaBeanTest.showThings()}"
oncomplete="presentData(data)"
immediate="true" />
</h:form>
js:
function presentData(data){
alert(data);
}
java:
@Name("javaBeanTest")
public class JavaBeanTest implements Serializable{
public boolean showThings(){
System.out.println("--JavaBeanTest.showThings()");
return true;
}
}
当点击「successed_test」按钮时,我在控制台上得到「true」警报和「--JavaBeanTest.showThings()」,但在点击「fail_test」时,我只在控制台上收到「undefined」警报和"--JavaBeanTest.showThins()"
显然,差异是形式内部或外部的。。。。。
困惑!!!!求你了!!!
ps.in在我的richfaces版本中,它使用"data"而不是"event.data",应该是3.x
JDK 1.6
JBDS 4.1.0GA
接缝2.2
JSF 1.2
在您的情况下,如果表单在表单中,HTML按钮会提交表单(不同浏览器的行为可能不同)。您需要明确指定按钮类型或阻止默认提交行为,例如:
<button id="fail" type="button" onclick="showMessage()">does not fail anymore</button>
或
<button id="fail" onclick="showMessage(); return false;">does not fail anymore</button>
W3C建议始终指定类型属性:
提示:始终指定元素的type属性。不同的浏览器可能使用不同的默认类型要素
请参阅:http://www.w3schools.com/tags/att_button_type.asp
相关文章:
- Javascript生成的表单未提交
- 如果ng单击附加到提交按钮,则表单未验证
- 表单未提交问题
- 表单未使用 MVC 提交任何值 Asp.Net
- Meteor JS自动表单自定义输入-没有当前视图
- 我的表单未将访问者引导至正确的页面
- 表单未在角度 js 中正确发布
- 图片上传无法在IE中工作,表单未提交
- 联系表单未发送表单值
- ajax和多个表单未提交
- 有两个输入的表单未提交
- 表单未提交即提交
- 在表单未传递的情况下使用.html()动态插入隐藏文本字段
- 表单未提交onclick事件
- JavaScript错误,表单未显示
- 表单未使用AJAX提交
- 表单未通过POST或GET提交数据
- WordPress插件表单未提交
- AngularJS嵌套控制器 - 表单未定义
- 自定义表单未在更改时提交