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
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
来源:https://stackoverflow.com/questions/6102577/how-to-submit-a-form-using-a-javascript-function-in-jsf-w-richfaces-w-o-the-fo