如何在带有Richfaces的JSF中使用JavaScript函数提交表单,而没有表单名称或ID? [英] How to submit a form using a javascript function in JSF w/ Richfaces, w/o the form name or id?

查看:89
本文介绍了如何在带有Richfaces的JSF中使用JavaScript函数提交表单,而没有表单名称或ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何在Richfaces 提交表单而不使用javascript中的表单名称或ID?我以为我可能可以使用jsFunction标记,但无法弄清楚.

How would I go about submitting a form in Richfaces without the form name or id from javascript? I was thinking I might be able to use the jsFunction tag, but I haven't been able to figure it out.

请注意,我可以在jsFunction中设置函数的名称

编辑 RF 3.3,JSF 1.2

EDIT RF 3.3, JSF 1.2

推荐答案

如果不重复表单ID,并且不知道表单在HTML DOM树中的确切位置(而不是您想要的元素),则无法实现提交表格.

That's not possible without repeating the form ID and without knowing the exact location of the form in the HTML DOM tree as opposed to the element from where you'd like to submit the form.

您最多可以使用EL功能rich:element().想象一下,您的表单是这样的:

You could at best use the EL function rich:element(). Imagine that you've a form like this:

<h:form id="myform">

然后您可以在JS上下文中(在JSF页面中!)按如下方式使用rich:element(),以HTML DOM元素的形式获取表单:

then you could use rich:element() as follows in JS context (in a JSF page!) to get the form as HTML DOM element:

<script>
    var form = #{rich:element('myform')};
    form.submit();
</script>

此获取即按如下方式生成到HTML

This get namely generated to the HTML as follows

<script>
    var form = document.getElementById('myformOrWhateverClientIdItHas');
    form.submit();
</script>

另请参见:

  • RichFaces内置客户端功能
  • See also:

    • RichFaces built-in client functions
    • 更新:或者,当JS函数由表单本身内部的元素调用时,只需使用this.form即可获取有关HTML DOM元素的父表单元素.例如

      Update: Or, when the JS function is invoked by an element inside the form itself, then just use this.form to get the parent form element of the HTML DOM element in question. E.g.

      <h:selectBooleanCheckbox onclick="doSomething(this.form)" />
      

      使用

      function doSomething(form) {
          // ...
          form.submit();
      }
      

      这篇关于如何在带有Richfaces的JSF中使用JavaScript函数提交表单,而没有表单名称或ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆