Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 850
Adam Avatar asked Jan 27 '26 06:01

Adam


2 Answers

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();
}
like image 158
BalusC Avatar answered Jan 28 '26 18:01

BalusC


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

like image 27
Max Katz Avatar answered Jan 28 '26 19:01

Max Katz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!