I'm trying to select and focus to choosed component ID after submit a form (ajax call).
<script>
var myFunc = function() {
document.getElementById('form:#{bean.componentId}').focus();
document.getElementById('form:#{bean.componentId}').select();
};
$(document).ready(function() {
myFunc();
});
</script>
<h:form id="form">
<h:commandButton action="#{bean.save}" onclick="return myFunc();" ...>
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
...
</h:form>
This solution is working, but problem is, that <f:ajax>
is called AFTER onclick
, so the the form is rendered after component selection, and focus is cleared.
How can I call my function AFTER the form is rendered?
update: (I've tried for example)
- add
onevent="myFunc();"
tof:ajax
=> leads to refreshing page - add
onevent="myFunc()"
tof:ajax
=> same behaviour asonclick
attribute - next
f:ajax
withonevent
attr. => still the same
update2 (how it should works):
- submit button is ajax called
- form is cleaned as needed
- appropriate field is focused (depended on some user choosed factors)