admin管理员组文章数量:1415653
I have a jsf page and a mandButton inside a form.
<h:form>
...
<h:mandButton action="#{mainViewController.showRelatedPayments()}" id="openpay" onclick="openModal();" value="Tst"></h:mandButton>
...
</h:form>
At the same jsf page i have a modal div..
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal titles</h4>
</div>
<div class="modal-body">
....
Dynamic content must be here
....
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
I have a javascript file also which includes the openModal() function.
function openModal() {
$('#myModal').modal('show');
}
When i click on the button, it calls the javascript function and the modal div shows up but then the page refreshing and the opening modal disappear..
The button also call my backing bean method:
public void showRelatedPayments() {
LOG.info("creating data for page..");
/*...
...
...
*/
}
What i would do is click on the button call the backing bean method which create data for the modal content and not refreshing the whole jsf page..
Is this possible? Could anybody please help me?
I have a jsf page and a mandButton inside a form.
<h:form>
...
<h:mandButton action="#{mainViewController.showRelatedPayments()}" id="openpay" onclick="openModal();" value="Tst"></h:mandButton>
...
</h:form>
At the same jsf page i have a modal div..
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal titles</h4>
</div>
<div class="modal-body">
....
Dynamic content must be here
....
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
I have a javascript file also which includes the openModal() function.
function openModal() {
$('#myModal').modal('show');
}
When i click on the button, it calls the javascript function and the modal div shows up but then the page refreshing and the opening modal disappear..
The button also call my backing bean method:
public void showRelatedPayments() {
LOG.info("creating data for page..");
/*...
...
...
*/
}
What i would do is click on the button call the backing bean method which create data for the modal content and not refreshing the whole jsf page..
Is this possible? Could anybody please help me?
Share Improve this question edited Dec 9, 2016 at 5:17 m 1987 1532 silver badges14 bronze badges asked May 14, 2015 at 8:13 solarenqusolarenqu 8144 gold badges22 silver badges47 bronze badges 1- you should probably start of by googling for ajax and jsf, I think there are some ponent / tags that are designed for that – Toskan Commented May 14, 2015 at 8:49
1 Answer
Reset to default 3<h:mandButton action="#{mainViewController.showRelatedPayments()}"
id="openpay" onclick="openModal();" value="Tst" />
That code does indeed this:
- Open modal dialog.
- Invoke mand button action to load data.
- Reload the whole page.
But you actually want this:
- Invoke mand button action to load data.
- Reload only the modal dialog.
- Open modal dialog.
You need to move around the tasks in the desired order and throw in ajax magic to achieve partial page reloads. The <f:ajax>
is helpful in this.
<h:mandButton action="#{mainViewController.showRelatedPayments()}"
id="openpay" value="Tst">
<f:ajax execute="@form" render=":relatedPayments"
onevent="function(data) { if (data.status == 'success') openModal(); }" />
</h:mandButton>
And add this to the modal dialog's content which should be dynamically updated.
<h:panelGroup id="relatedPayments" layout="block">
....
Dynamic content must be here
....
</h:panelGroup>
本文标签: jqueryJsf commandbutton call javascript function then refreshing the whole pageStack Overflow
版权声明:本文标题:jquery - Jsf commandbutton call javascript function then refreshing the whole page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745156830a2645225.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论