How to submit a form using a javascript function in JSF w Richfaces, wo the form name or id? - Stack Overflow

admin2025-03-14  4

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

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

Share Improve this question edited May 23, 2011 at 21:30 BalusC 1.1m376 gold badges3.6k silver badges3.6k bronze badges asked May 23, 2011 at 20:21 AdamAdam 3,7958 gold badges46 silver badges79 bronze badges 1
  • RichFaces 3.3.x or 4.x? JSF 1.x or 2.x? – BalusC Commented May 23, 2011 at 20:25
Add a ment  | 

3 Answers 3

Reset to default 3

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

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1741942438a188962.html

最新回复(0)