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

 ̄綄美尐妖づ 提交于 2019-12-06 11:06:33

问题


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.

As a note, I can set the name of the function in jsFunction

EDIT RF 3.3, JSF 1.2


回答1:


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:

  • RichFaces built-in client functions

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();
}



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/6102577/how-to-submit-a-form-using-a-javascript-function-in-jsf-w-richfaces-w-o-the-fo

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