How to submit a form using a javascript function in JSF w/ Richfaces, w/o the form name or id?

一曲冷凌霜 提交于 2019-12-04 18:04:56

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.

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

<h:form id="myform">

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>

This get namely generated to the HTML as follows

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

See also:


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)" />

with

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

You don't need the form name or id to submit using a4j:jsFunction.

If you want to use a4j:jsFunction, don't forget to add execute="@form" in order to submit all form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!