Do you really need to submit a form ajaxically? That's where the jsf.ajax.request()
is for. It seems like that you just want to load some static content inside some <div>
. Just do as follows
<script>
$(document).ready(function() {
$.get("#{request.contextPath}/myCommunity/ajax/hotTopicDiscussion.faces", function(data) {
$("#discussionTopic").html(data);
});
});
</script>
<h:panelGroup id="discussionTopic" layout="block" />
Or, simpler, with jQuery.load()
:
<script>
$(document).ready(function() {
$("#discussionTopic").load("#{request.contextPath}/myCommunity/ajax/hotTopicDiscussion.faces");
});
</script>
<h:panelGroup id="discussionTopic" layout="block" />
In both cases, I assume that the hotTopicDiscussion.xhtml
has <ui:composition>
as root element and that it contains only the necessary HTML (and thus not <html>
and so on).
If you indeed really need to submit a form ajaxically, then simplest would be to let JS "click" the button programmatically. It will delegate all the way up to the proper and needed jsf.ajax.request()
call. A jsf.ajax.request()
call is useless anyway without a physical form/button component on the page. You can if necessary hide the form by CSS.
<script>
$(document).ready(function() {
$("[id='form:button']")[0].onclick();
});
</script>
<h:form id="form" style="display:none;">
<h:commandButton id="button" action="#{bean.submit}">
<f:ajax render=":discussionTopic" />
</h:commandButton>
</h:form>
<h:panelGroup id="discussionTopic" layout="block" />